Pagini recente » Cod sursa (job #1506890) | Cod sursa (job #831657) | Cod sursa (job #2279688) | Cod sursa (job #1172508) | Cod sursa (job #1184844)
#include<cstdio>
const int N=1000000,K=666013;
class Hash{
public:
int list[K+1],val[K+1],next[K+1];
int nr;
inline void push(int x){
int r=x%K;
this->val[++this->nr]=x;
this->next[nr]=this->list[r];
this->list[r]=this->nr;
}
inline void pop(int x){
int r=x%K,p;
if(x==val[list[r]])
list[r]=next[list[r]];
else{
p=list[r];
while(next[p]!=0&&val[next[p]]!=x)
p=next[p];
next[p]=next[next[p]];
}
}
inline bool belong(int x){
int p=list[x%K];
while(p!=0&&val[p]!=x)
p=next[p];
return p!=0;
}
};
Hash h;
FILE*in,*out;
int n;
void init(){
in=fopen("hashuri.in","r");
out=fopen("hashuri.out","w");
fscanf(in,"%d",&n);
}
int main(){
int q,x;
init();
while(n>0){
fscanf(in,"%d%d",&q,&x);
if(q==1){
if(!h.belong(x))
h.push(x);
}
else if(q==2){
if(h.belong(x))
h.pop(x);
}
else
if(h.belong(x))
fprintf(out,"1\n");
else
fprintf(out,"0\n");
n--;
}
return 0;
}