Pagini recente » Cod sursa (job #1649522) | Cod sursa (job #420779) | Cod sursa (job #630498) | Cod sursa (job #471538) | Cod sursa (job #1191021)
#include <fstream>
#define Mod 666013
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
struct point
{
int inf;
point *leg;
};
point *p,*q,*u,*prim,*h[1000000];
int a,b,n,i,ind;
bool ok(int x, int ind)
{
for(p=h[ind]; p!=NULL; p=p->leg)
if(p->inf==x) return true;
return false;
}
void sterge(int x,int ind)
{point *u,*t;
u=NULL;
p=h[ind];
while (p!=NULL && p->inf!=x)
{
u=p;
p=p->leg;
}
if (h[ind]!=NULL && h[ind]->inf==x)
{
t=h[ind];
h[ind]=h[ind]->leg;
delete t;
}
else if(p!=NULL)
{
u->leg=p->leg;
delete p;
}
}
int main()
{f>>n;
for (i=1;i<=1000000;i++) h[i]=NULL;
for (i=1;i<=n;i++)
{f>>a>>b;
ind=b%Mod;
if (a==1 && !ok(b,ind))
{ q=new point;
q->leg=h[ind];
q->inf=b;
h[ind]=q;
}
if (a==2 && ok(b,ind)) sterge(b,ind);
if (a==3) {if (ok(b,ind)==true) g<<1<<'\n';
else g<<0<<'\n';}
}
f.close();
g.close();
return 0;
}