Pagini recente » sda | Cod sursa (job #2841591) | Cod sursa (job #2004952) | Cod sursa (job #111818) | Cod sursa (job #1294479)
#include <cstdio>
using namespace std;
const int MAX_N = 10000000;
const int p1 = 666013, p2 = 300007;
FILE *in, *out;
int h[MAX_N];
void adauga(int x)
{
int poz = x%p1, m = x%p2;
while(h[poz] > 0)
{
poz += m;
if(poz >= MAX_N)
poz -= MAX_N;
}
h[poz] = x;
}
int exista(int x)
{
int poz = x%p1, m = x%p2;
while(h[poz] != 0)
{
if(h[poz] == x) return poz;
poz += m;
if(poz >= MAX_N)
poz -= MAX_N;
}
return -1;
}
void sterge(int x)
{
int poz = exista(x);
if(poz != -1)
h[poz] = -1;
}
int main()
{
in = fopen("hashuri.in", "r");
out = fopen("hashuri.out", "w");
int n, x, t;
fscanf(in, "%d", &n);
while(n > 0)
{
if(n%100000 == 0)
{
n++;
n--;
}
fscanf(in, "%d%d", &t,&x);
if(t == 1)
adauga(x);
else if(t == 2)
sterge(x);
else
fprintf(out, "%d\n", (exista(x)==-1)?0:1);
n--;
}
return 0;
}