Pagini recente » Cod sursa (job #2026964) | Cod sursa (job #2157625) | Cod sursa (job #2847190) | Cod sursa (job #1907585) | Cod sursa (job #1972231)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000001;
const int MOD2 = 666013;
const int MOD1 = 10007;
int h[MAXN];
bool hash_find(int nod){
int where1 = nod % MOD1;
int where2 = nod % MOD2;
return h[where1]==nod || h[where2]==nod;
}
void hash_insert(int nod){
int where1 = nod % MOD1;
int where2 = nod % MOD2;
if(!h[where1]){
h[where1] = nod;
return;
}
if(!h[where2]){
h[where2] = nod;
return;
}
}
void hash_remove(int nod){
int where1 = nod % MOD1;
int where2 = nod % MOD2;
if(h[where1] == nod){
h[where1] = 0;
}
if(h[where2] == nod){
h[where2] = 0;
}
}
int q;
int main(){
ifstream in("hashuri.in");
ofstream out("hashuri.out");
in>>q;
while(q--){
int op, param;
in>>op>>param;
if(op == 1){
hash_insert(param);
} else if(op == 2){
hash_remove(param);
} else {
out<< hash_find(param)<<'\n';
}
}
return 0;
}