Cod sursa(job #1472589)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 17 august 2015 13:19:59
Problema Hashuri Scor 100
Compilator c Status done
Runda Arhiva educationala Marime 0.94 kb
#include<stdio.h>
#include<stdlib.h>
typedef struct O {
	int I;
	struct O *U;
}N;
int n,y,i,x;
N *h[1000001],*u,*p,*q;
int F(N *l,int y) {
	for(N *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);
	for(i=1;i<=n;i++) {
		scanf("%d%d",&x,&y);
      	if(x==1) {
		  	if(!F(h[y%1000001],y)) {
                u=(N*)malloc(sizeof(N));
                u->U=h[y%1000001],u->I=y,h[y%1000001]=u;
		  	}
		}
      	else if(x==2) {
            if(F(h[y%1000001],y)) {
                for(p=q=h[y%1000001];p&&p->I!=y;q=p,p=p->U);
                if(p) {
                    if(q==p)
                        h[y%1000001]=h[y%1000001]->U;
                    else
                        q->U=p->U;
                    free(p);
                }
            }
        }
        else
            printf("%d\n",F(h[y%1000001],y));
	}
}