Cod sursa(job #2622252)

Utilizator MevasAlexandru Vasilescu Mevas Data 31 mai 2020 19:08:39
Problema Hashuri Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.03 kb
#include <vector>
#include <fstream>

#define MOD 666013

using namespace std;

vector<int> map[MOD];

vector<int>::iterator find(int x) {
    int hash = x % MOD;
    vector<int>::iterator it;

    for(it = map[hash].begin(); it != map[hash].end(); ++it)
        if(*it == x)
            return it;

    return map[hash].end();
}

void insert(int x) {
    int hash = x % MOD;
    if(find(x) == map[hash].end())
        map[hash].push_back(x);
}

void erase(int x) {
    int hash = x % MOD;
    vector<int>::iterator it = find(x);

    if(it != map[hash].end())
        map[hash].erase(it);
}

int main() {
    ifstream fin("hashuri.in");
    ofstream fout("hashuri.out");

    int op, x, n;
    fin >> n;

    for(int i = 0; i < n; i++) {
        fin >> op >> x;
        if(op == 1) {
            insert(x);
            continue;
        }
        if(op == 2) {
            erase(x);
            continue;
        }
        fout << (find(x) != map[x % MOD].end()) << endl;
    }

    return 0;
}