Pagini recente » Cod sursa (job #1047928) | Cod sursa (job #2786806) | Cod sursa (job #766660) | Cod sursa (job #2085552) | Cod sursa (job #1161630)
#include <cstdio>
#define MOD 666013
using namespace std;
int hash[MOD][6];
void insert(int x);
void sterge(int x);
int check(int x);
int main()
{
int n,i,op,x;
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d",&n);
for(i=1;i<=n;++i)
{
scanf("%d%d",&op,&x);
if(op==1)insert(x);
if(op==2)sterge(x);
if(op==3)
if(check(x)==-1)
printf("0\n");
else
printf("1\n");
}
return 0;
}
void insert(int x)
{
int i;
i=check(x);
if(i==-1)
hash[x%MOD][++hash[x%MOD][0]]=x;
}
void sterge(int x)
{
int poz= x%MOD, i;
i=check(x);
if(i!=-1)
hash[poz][i]=-1;
}
int check(int x)
{
int j;
int poz=x%MOD,i,gata=0;
for(i=1; i<=hash[poz][0]; i++)
if(hash[poz][i]==x)
{gata=1;break;}
if(gata==1)
{
for(j=i;j<=hash[poz][0];++j)hash[poz][j]=hash[poz][j+1];
hash[poz][0]--;
return i;
}
return -1;
}