Pagini recente » Cod sursa (job #861398) | Cod sursa (job #2982419) | Cod sursa (job #1915133) | Cod sursa (job #1102987) | Cod sursa (job #1729955)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("hashuri.in");
ofstream t ("hashuri.out");
int32_t v[10000001];
const int key=21313;
inline int32_t hashcode(int32_t x){
return (x*key+key/x)%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;
}