Cod sursa(job #2306061)
| Utilizator | Data | 21 decembrie 2018 16:21:39 | |
|---|---|---|---|
| Problema | Hashuri | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.78 kb |
#include<cstdio>
#define M 666013
struct N
{
int I;
N *U;
};
int n,y,x,o;
N *h[M],*p,*q;
int main()
{
freopen("hashuri.in","r",stdin),freopen("hashuri.out","w",stdout),scanf("%d",&n);
while(n--)
{
scanf("%d%d",&x,&y);
for(o=0,p=h[y%M];p&&!o;p=p->U)
if(p->I==y)
o=1;
if(x==1&&!o)
{
p=new N;
p->U=h[y%M],p->I=y,h[y%M]=p;
continue;
}
if(x==2&&o)
{
for(p=q=h[y%M];p&&p->I!=y;q=p,p=p->U);
if(p)
{
if(q==p)
h[y%M]=h[y%M]->U;
else
q->U=p->U;
delete p;
}
continue;
}
printf("%d\n",o);
}
}
