Pagini recente » Cod sursa (job #686108) | Cod sursa (job #1334875) | Cod sursa (job #888390) | Cod sursa (job #2787404) | Cod sursa (job #1233369)
#include<cstdio>
#define R 666013
using namespace std;
int lst[R];
int v[1000001];
int urm[1000001];
int n,m;
bool cauta(int x){
int tip=x%R,p;
p=lst[tip];
while(p!=0){
if (v[p]==x) return 1;
p=urm[p];
}
return 0;
}
void adauga(int x){
int tip=x%R;
if (cauta(x)==1) return ;
m++;
v[m]=x;
urm[m]=lst[tip];
lst[tip]=m;
}
void sterge(int x){
int tip=x%R,p;
p=lst[tip];
if (v[p]==x) lst[tip]=urm[p];
while(urm[p]!=0 &&urm[p]!=x){
p=urm[p];
}
if (urm[p]==x) urm[p]=urm[urm[p]];
}
int main(){
freopen ("hashuri.in","r",stdin);
freopen ("hashuri.out","w",stdout);
int i,op,x;
scanf ("%d",&n);
for(i=1;i<=n;i++){
scanf ("%d%d",&op,&x);
if (op==1) adauga(x);
else
if (op==2) sterge(x);
else printf ("%d\n",cauta(x));
}
return 0;
}