Cod sursa(job #2306077)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 21 decembrie 2018 16:35:58
Problema Hashuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include<cstdio>
#define M 1000001
typedef struct O 
{
    int I;
    struct O *U;
}N;
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) 
		{
            if(!o) 
			{
                p=new N;
                p->U=h[y%M],p->I=y,h[y%M]=p;
            }
        }
        else if(x==2) 
		{
            if(o) 
			{
                for(p=q=h[y%M];p&&p->I!=y;q=p,p=p->U);
                if(q==p)
                    p=p->U;
                else
                    q->U=p->U;
            }
        }
        else
            printf("%d\n",o);
    }
}