Pagini recente » Cod sursa (job #907855) | Cod sursa (job #510060) | Cod sursa (job #707070) | Cod sursa (job #529969) | Cod sursa (job #1294463)
#include <cstdio>
FILE* in=fopen("hashuri.in","r");
FILE* out=fopen("hashuri.out","w");
const int p1=666013,p2=300007,Q=1000007;
int h[Q];
int n;
void add(int x)
{
int poz=x%p1,m=x%p2;
while(h[poz]>0)
{
poz+=m;
if(poz>=n)
poz-=n;
}
h[poz]=x;
}
bool exista(int x)
{
int poz=x%p1,m=x%p2;
while(h[poz]!=0)
{
if(h[poz]==x)
return 1;
poz+=m;
if(poz>=n)
poz-=n;
}
return 0;
}
void delet(int x)
{
int poz=x%p1,m=x%p2;
while(h[poz]!=0)
{
if(h[poz]==x)
{
h[poz]=-1;
return;
}
poz+=m;
if(poz>=n)
poz-=n;
}
}
int main()
{
fscanf(in,"%d",&n);
int t,x;
for(int i=1; i<=n; i++)
{
fscanf(in,"%d%d",&t,&x);
if(t==1)
{
if(!exista(x))
add(x);
}
if(t==2)
{
delet(x);
}
if(t==3)
fprintf(out,"%d\n",exista(x));
}
return 0;
}