Pagini recente » Cod sursa (job #471072) | Cod sursa (job #877415) | Cod sursa (job #142896) | Cod sursa (job #2817827) | Cod sursa (job #1550096)
#include <fstream>
#define p 666013;
#include <cmath>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int n,i,x,y,v[2][1000001],k,viz[44723],h[666014],nr;
void aloc(int x,int nr)
{
v[1][nr]=y;
}
void sterge(int x)
{
for(int i=1;i<=k;i++)
if(v[1][i]==y)
v[1][i]=-1;
}
void hashing(int x,int nr2)
{
int rest=1;
for(int i=1;i<=nr2;i++)
{
rest=v[1][i]%p;
v[2][i]=h[rest];
h[rest]=i;
}
}
int cauta(int x)
{
int c=1;
int rest=1;
if(v[2][rest]==0)
return 0;
rest=h[x];
c=v[1][rest];
if(c==x)
return 1;
else
return cauta(v[2][rest]);
}
int main()
{
fin>>n;
for(i=1;i<=n;i++)
{
fin>>x>>y;
if(x==1)
{k++;aloc(x,k);}
if(x==2)
sterge(y);
if(x==3)
{
hashing(y,k);
fout<<cauta(y)<<endl;
}
}
}