Pagini recente » Cod sursa (job #2721560) | Cod sursa (job #3243245) | Cod sursa (job #3236356) | Cod sursa (job #2679799) | Cod sursa (job #774790)
Cod sursa(job #774790)
#include<stdio.h>
const int m=666013;
using namespace std;
int n,i,c;
long e;
struct hash
{long x;
hash* next;};
hash* h[666013];
void add(long elem)
{hash* q = new hash;
int modl;
q->x=elem;
modl=e%m;
q->next=h[modl];
h[modl]=q;
}
int search(long elem)
{int modl;
modl=e%m;
hash* q=h[modl];
while(q)
{if(q->x==elem)
return 1;
q=q->next;}
return 0;
}
void del(int elem)
{int modl;
modl=e%m;
hash* q=h[modl];
if(q)
{if(q->x==elem)
h[modl]=q->next;
else
{hash* p;
p=q;
q=q->next;
while(q)
{if(q->x==elem)
p->next=q->next;
q=q->next;}
}
}
}
int main()
{freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d",&n);
for(i=1; i<=n; i++)
{scanf("%d %d",&c,&e);
if(c==1)
add(e);
if(c==2)
del(e);
if(c==3)
printf("%d\n",search(e));
}
return 0;
}