Cod sursa(job #2382020)

Utilizator AndreiVisoiuAndrei Visoiu AndreiVisoiu Data 17 martie 2019 16:19:36
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.92 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("hashuri.in");
ofstream out("hashuri.out");

const int MOD = 666013;

list<int> L[MOD];
int N;

list<int>::iterator hashMap_find(int x) {
    int lst = x % MOD;

    for(auto it = L[lst].begin(); it != L[lst].end(); ++it)
        if(*it == x)
            return it;
    return L[lst].end();
}

void hashMap_insert(int x) {
    int lst = x % MOD;

    if(hashMap_find(x) == L[lst].end())
        L[lst].push_back(x);
}

void hashMap_delete(int x) {
    int lst = x % MOD;
    auto it = hashMap_find(x);

    if(it != L[lst].end())
        L[lst].erase(it);
}

int main()
{
    in >> N;

    int op, x;
    while(N--) {
        in >> op >> x;
        if(op == 1)
            hashMap_insert(x);
        else if(op == 2)
            hashMap_delete(x);
        else out << (hashMap_find(x) != L[x%MOD].end()) << '\n';
    }
    return 0;
}