Pagini recente » Diferente pentru utilizator/djok intre reviziile 141 si 111 | Monitorul de evaluare | Istoria paginii utilizator/cnteste | Profil Andrei-27 | Cod sursa (job #1472589)
#include<stdio.h>
#include<stdlib.h>
typedef struct O {
int I;
struct O *U;
}N;
int n,y,i,x;
N *h[1000001],*u,*p,*q;
int F(N *l,int y) {
for(N *p=l;p;p=p->U)
if(p->I==y)
return 1;
return 0;
}
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)) {
u=(N*)malloc(sizeof(N));
u->U=h[y%1000001],u->I=y,h[y%1000001]=u;
}
}
else if(x==2) {
if(F(h[y%1000001],y)) {
for(p=q=h[y%1000001];p&&p->I!=y;q=p,p=p->U);
if(p) {
if(q==p)
h[y%1000001]=h[y%1000001]->U;
else
q->U=p->U;
free(p);
}
}
}
else
printf("%d\n",F(h[y%1000001],y));
}
}