Pagini recente » Cod sursa (job #2590863) | Cod sursa (job #2619419) | Cod sursa (job #3183186) | Cod sursa (job #242629) | Cod sursa (job #2846265)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int MAX=1e6+5;
const int P=666013;
int n,op,x;
struct nod
{
int info;
nod *urm;
}*H[P];
void adauga(int x)
{
int xmod=x%P;
nod *u=new nod;
u->info=x;
u->urm=H[xmod];
H[xmod]=u;
}
void sterge(int x)
{
int xmod=x%P;
nod *p;
if(H[xmod]->info==x)
{
p=H[xmod];
H[xmod]=H[xmod]->urm;
delete p;
return;
}
for(p=H[xmod];p->urm;p=p->urm)
if(p->urm->info==x)
{
nod q=p->urm;
p->urm=p->urm->urm;
delete q;
return;
}
}
bool apare(int x)
{
int xmod=x%P;
for(nod *p=H[xmod];p;p=p->urm)
while(p)
if(p->info==x)
return 1;
return 0;
}
int main()
{
fin >> n;
while(n--)
{
fin >> op >> x;
switch(op)
{
case 1 : if(!apare(x)) adauga(x); break;
case 2 : if(apare(x)) sterge(x); break;
case 3 : fout << apare(x) << '\n'; break;
}
}
return 0;
}