Cod sursa(job #1970119)

Utilizator andreigasparoviciAndrei Gasparovici andreigasparovici Data 18 aprilie 2017 21:55:25
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.93 kb
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1000001;
const int MOD = 666013;

vector<int> h[MOD];

bool hash_find(int nod){
    int where = nod % MOD;
    return find(h[where].begin(), h[where].end(), nod) != h[where].end();
}

void hash_insert(int nod){
    int where = nod % MOD;
    if(!hash_find(nod)){
        h[where].push_back(nod);
    }
}

void hash_remove(int nod){
    int where = nod % MOD;
    auto it = find(h[where].begin(), h[where].end(), nod);
    if(it == h[where].end())
        return;
    h[where].erase(it);
}

int q;

int main(){
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);
    scanf("%d ", &q);
    while(q--){
        int op,  param;
        scanf("%d %d", &op, &param);
        if(op == 1){
            hash_insert(param);   
        } else if(op == 2){
            hash_remove(param);
        } else {
           printf("%d\n", hash_find(param)); 
        }
    }
}