Cod sursa(job #2622234)

Utilizator MevasAlexandru Vasilescu Mevas Data 31 mai 2020 18:53:30
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.99 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;
    auto 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);
        } else if(op == 2) {
            erase(x);
        } else if(op == 3) {
            fout << (find(x) != map[x % MOD].end()) << endl;
        }
    }

    return 0;
}