Cod sursa(job #2306105)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 21 decembrie 2018 17:03:33
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.5 kb
#include<cstdio>
#define M 666013
typedef struct O 
{
    int I;
    O *U;
}N;
int n,y,x,z;
N *h[M],*p,*q;
int main() 
{
    freopen("hashuri.in","r",stdin),freopen("hashuri.out","w",stdout),scanf("%d",&n);
    while(n--) 
	{
        for(scanf("%d%d",&x,&y),z=y%M,p=q=h[z];p&&p->I!=y;q=p,p=p->U);
        if(x==1&&!p)
            p=new N,p->U=h[z],p->I=y,h[z]=p;
        else if(x==2&&p) 
            q==p?h[z]=h[z]->U:q->U=p->U;
        else if(x==3)
            printf("%d\n",p?1:0);
    }
}