Cod sursa(job #2306047)

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