Cod sursa(job #2889992)

Utilizator tiberiusss26Titiriga Tiberiu Nicolae tiberiusss26 Data 14 aprilie 2022 00:56:01
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.09 kb
#include <iostream>
#include <fstream>
#include<vector>

using namespace std;
#define MOD 666013

vector<int> hashh[MOD];


vector<int>::iterator gasesteVal(int x) {
    int y = x % MOD;
    vector<int>::iterator it;
    for (it = hashh[y].begin(); it != hashh[y].end(); it++) {
        if (*it == x)
            return it;
    }
    return hashh[y].end();
}

void adaugaVal(int x) {
    int y = x % MOD;
    if (gasesteVal(x) == hashh[y].end())
        hashh[y].push_back(x);
}

void stergeVal(int x) {
    int y = x % MOD;
    if (gasesteVal(x) != hashh[y].end())
        hashh[y].erase(gasesteVal(x));
}

void afis(){
    for(auto it:hashh[MOD])
        cout<<it<<" ";
}

int main() {
    long long N;
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    f >> N;
    long long x, y;
    hashh[10].push_back(10);
    for (int i = 0; i < N; i++) {
        f >> x >> y;
        if (x == 1) {
            adaugaVal(y);
            continue;
        }
        if (x == 2) {
            stergeVal(y);
            continue;
        }
        g << (gasesteVal(y) != hashh[ y % MOD].end()) << "\n";
    }


}