Pagini recente » Cod sursa (job #176099) | Profil 4claudiac9491tr2 | Cod sursa (job #170856) | Statisticile problemei Mofocarburi | Cod sursa (job #1472583)
#include<stdio.h>
#include<stdlib.h>
typedef struct O {
int I;
O *U;
}N;
int n,y,i,x;
N *h[1000001];
int F(N *l,int y) {
for(N *p=l;p;p=p->U)
if(p->I==y)
return 1;
return 0;
}
void A(N *&l,int y) {
N *u=(N*)malloc(sizeof(N));
u->U=l,u->I=y,l=u;
}
void D(N *&l,int y) {
N *p=l,*q=l;
while(p&&p->I!=y)
q=p,p=p->U;
if(p) {
if(q==p)
l=l->U;
else
q->U=p->U;
free(p);
}
}
int main() {
freopen("hashuri.in","r",stdin),freopen("hashuri.out","w",stdout),scanf("%d",&n);
for(i=1;i<=n;i++) {
scanf("%d%d",&x,&y);
if(x==1) {
if(!F(h[y%1000001],y))
A(h[y%1000001],y);
}
else if(x==2) {
if(F(h[y%1000001],y))
D(h[y%1000001],y);
}
else
printf("%d\n",F(h[y%1000001],y));
}
}