Pagini recente » Cod sursa (job #55461) | Cod sursa (job #2238690) | Cod sursa (job #2542046) | Cod sursa (job #71251) | Cod sursa (job #1294473)
#include <cstdio>
FILE* in=fopen("hashuri.in","r");
FILE* out=fopen("hashuri.out","w");
const int p1=666013,p2=666019,Q=1000007;
const int N=12000000;
int h[N+14];
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;
}