Pagini recente » Cod sursa (job #787002) | Cod sursa (job #283459) | Cod sursa (job #2079368) | Cod sursa (job #1383575) | Cod sursa (job #2586869)
#include<cstdio>
using namespace std;
const int N = 1000001;
const int M = 666019;
int val[N], urm[N], lst[M], nr;
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 c = x % M;
val[ ++ nr ] = x;
urm[nr] = lst[c];
lst[c] = nr;
}
void sterge(int x)
{
int c = x % M;
int 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 main()
{
int nr , p;
freopen("hashuri.in" , "r" , stdin);
freopen("hashuri.out" , "w" , stdout);
int n;
scanf("%d" , &n);
for(int i = 1; i <= n ; i ++)
{
scanf("%d%d" , &p , &nr);
if(p == 1)
{
adauga(nr);
}
if(p == 2)
{
sterge(nr);
}
if(p == 3)
{
printf("%d\n" , apartine(nr));
}
}
return 0;
}