Cod sursa(job #1472583)

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