Pagini recente » Cod sursa (job #3249225) | Cod sursa (job #924927) | Cod sursa (job #487018) | Cod sursa (job #2750852) | Cod sursa (job #1729957)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("hashuri.in");
ofstream t ("hashuri.out");
int32_t v[10000010];
const int key=21313;
inline int32_t hashcode(int32_t x){
return (x*key+x/key)%10000000;}
inline void increment(int &a){
if (++a==10000000) a=0;
}
inline void hash_add(int32_t x){int32_t i=hashcode(x);
while(v[i]!=0){
if (v[i]==x)return;
increment(i);
}
v[i]=x;
}
inline void hash_erase(int32_t x){int32_t i=hashcode(x);
while(v[i]!=0){
if (v[i]==x)v[i]=-1;
increment(i);
}}
inline bool hash_verify(int32_t x){int32_t i=hashcode(x);
while(v[i]!=0){
if (v[i]==x)return 1;
increment(i);
}
return 0;
}
int main()
{int32_t n,q,x;
f>>n;
for (int i=0;i<n;++i){
f>>q>>x;
if (q==1)
hash_add(x);
else if(q==2)
hash_erase(x);
else if(q==3)
t<<hash_verify(x)<<'\n';}
return 0;
}