Pagini recente » Cod sursa (job #128287) | Cod sursa (job #557394) | Cod sursa (job #2855361) | Cod sursa (job #666123) | Cod sursa (job #2627279)
#include <bits/stdc++.h>
using namespace std;
const int N=1000000, M=666019;
FILE *fin, *fout;
int nr=0;
int lst[M], val[N], urm[N];
bool apartine(int x)
{
int c=x%M;
for(int p=lst[c]; p!=0; p=urm[p])
{
if(val[p]==x) return true;
}
return false;
}
void adauga(int x)
{
if(apartine(x)) return;
int p = x % M;
val[++nr] = x;
urm[nr] = lst[p];
lst[p] = nr;
}
void sterge(int x)
{
int r=x%M, p=lst[r];
while(p!=0 && val[p]!=x)
{
p=urm[p];
}
if(p!=0)
{
val[p]=val[lst[r]];
lst[r]=urm[lst[r]];
}
}
int main()
{
fin=fopen("hashuri.in", "r");
fout=fopen("hashuri.out", "w");
int n, x, p;
fscanf(fin, "%d", &n);
for(int i=1; i<=n; i++)
{
fscanf(fin, "%d%d", &p, &x);
if(p==1)
{
adauga(x);
}
else if(p==2)
{
sterge(x);
}
else fprintf(fout, "%d\n", apartine(x));
}
return 0;
}