Pagini recente » Istoria paginii utilizator/mihaiteisanu03 | Cod sursa (job #1505874) | Cod sursa (job #3212440) | Cod sursa (job #1795879) | Cod sursa (job #280079)
Cod sursa(job #280079)
#include<stdio.h>
#define hmax 1000001
#define nmax 1000*1001
struct lista
{
int p,v;
}l[nmax];
int t[hmax];
int nr;
int n;
int cod_hash(int x)
{
return x%hmax;
}
int cauta_hash(int c,int x)
{
int ul;
for(ul=t[c];ul;ul=l[ul].p)
if(l[ul].v==x) return ul;
return 0;
}
void add_hash(int x)
{
int ul,c=cod_hash(x);
if(!cauta_hash(c,x))
{
l[nr++].p=t[c];
l[nr].v=x;
t[c]=nr;
}
}
void del_hash(int x)
{
int ul=cauta_hash(cod_hash(x),x);
if(ul) l[ul].v=0;
}
int main()
{
int o,x;
FILE *in=fopen("hashuri.in","rt");
FILE *out=fopen("hashuri.out","wt");
fscanf(in,"%d",&n);
while(n--)
{
fscanf(in,"%d %d",&o,&x);
if(o==1) add_hash(x);
else if(o==2) del_hash(x);
else if(cauta_hash(cod_hash(x),x)) fprintf(out,"1\n");
else fprintf(out,"0\n");
}
fclose(in);
fclose(out);
return 0;
}