Pagini recente » Cod sursa (job #587747) | Cod sursa (job #2543066) | Cod sursa (job #83126) | Cod sursa (job #1598216) | Cod sursa (job #2588831)
#include <fstream>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
const int N=1000001;
const int M=666019;
int lst[M], urm[N], val[N], nr;
bool apartine(int x)
{
int c=x%M;
for(int p=lst[c]; p!=0; p=urm[p])
{
if(val[p]==c)
{
return true;
}
}
return false;
}
void adauga(int x)
{
int c = x % M;
if(apartine(x))
return;
val[++nr]=x;
urm[nr]=lst[c];
lst[c]=nr;
}
void sterge (int x)
{
int c= x % M, p=lst[c];
while(p!=0 && val[p]!=x)
{
p=urm[p];
}
if(p!=0)
{
val[p]=val[lst[c]];
lst[c]=urm[lst[c]];
}
}
int ct, t;
int main()
{
in>>t;
for(int i=1; i<=t; i++)
{
int x;
in>>ct>>x;
if(ct==1)
adauga(x);
else if(ct==2)
sterge(x);
else if(ct==3)
{
int ok = apartine(x);
if(ok == 1)
{
out << "1\n";
}
else
out << "0\n";
}
}
return 0;
}