Cod sursa(job #2890407)

Utilizator hobbitczxdumnezEU hobbitczx Data 15 aprilie 2022 15:07:37
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.07 kb
#include <bits/stdc++.h>
#define ll long long
#define INF 0x3F3F3F3F
using namespace std;

const string fisier = "hashuri";

ifstream fin (fisier + ".in");
ofstream fout (fisier + ".out");

const int mod = 666013;

vector<int>g[mod];

auto gasesteHash (int x){
    int y = x % mod;
    for (auto it = g[y].begin(); it != g[y].end(); ++it){
        if (*it == x){
            return it;
        }
    }
    return g[y].end();
}
void adaugaHash (int x){
    int y = x % mod;
    if (gasesteHash(x) == g[y].end()){
        g[y].push_back(x);
    }
}

void stergeHash (int x){
    int y = x % mod;
    if (gasesteHash(x) != g[y].end()){
        g[y].erase(gasesteHash(x));
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    int q; fin >> q;
    while (q--){
        int op , x; fin >> op >> x;
        if (op == 1){
            adaugaHash(x);
            continue;
        }
        else if (op == 2){
            stergeHash(x);
            continue;
        }
        fout << (gasesteHash(x) != g[x % mod].end()) << '\n';
    }
}