Cod sursa(job #2306083)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 21 decembrie 2018 16:45:06
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include<cstdio>
#define M 666013
typedef struct O 
{
    int I;
    struct O *U;
}N;
int n,y,x;
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(p=q=h[y%M];p&&p->I!=y;q=p,p=p->U);
        if(x==1&&(!p||(p&&p->I!=y)))
		{
            p=new N;
            p->U=h[y%M],p->I=y,h[y%M]=p;
            continue;
        }
        if(x==2&&p&&p->I==y) 
		{
            q==p?h[y%M]=h[y%M]->U:q->U=p->U;
            continue;
        }
        if(x==3)
            printf("%d\n",p&&p->I==y?1:0);
    }
}