Pagini recente » Cod sursa (job #1456990) | Cod sursa (job #3148264) | Cod sursa (job #409886) | Cod sursa (job #1605797) | Cod sursa (job #806032)
Cod sursa(job #806032)
#include <iostream>
#include <fstream>
#include <cstdio>
using namespace std;
const int MOD = 1 << 20;
int n;
struct nod
{
int val;
nod *urm;
} * a[MOD];
void add(int x)
{
int y=x%MOD;
nod *p=new nod;
p->val=x;
p->urm=a[y];
a[y]=p;
}
int caut(int x)
{
int y=x%MOD;
if(a[y]==NULL)return 0;
if(a[y]->val==x)return 1;
nod *p=a[y];
while(p->urm)
{
p=p->urm;
if(p->val==x)return 1;
}
return 0;
}
void del(int x)
{
int y=x & (MOD-1);
nod *p;
if(a[y]->val==x)
{
p=a[y];
a[y]=a[y]->urm;
delete p;
return;
}
for(p=a[y];p->urm;p= p->urm)
{
if(p->urm->val==x)
{
nod *q=p->urm;
p->urm=q->urm;
delete q;
return;
}
}
}
int main()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
int c,x;
scanf("%d",&n);
while(n--)
{
scanf("%d %d",&c,&x);
if(c==1){if(caut(x)==0)add(x);}
else if(c==2) {if(caut(x)==1)del(x);}
else
{
printf("%d",caut(x));
printf("\n");
}
}
}