Pagini recente » Cod sursa (job #1250357) | Cod sursa (job #1273675) | Cod sursa (job #613410) | Cod sursa (job #87123) | Cod sursa (job #2580872)
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1000001;
const int K = 666019;
int nr;
int urm[N], val[N], lst[K];
bool apartine(int x){
int c = x % K;
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 % K;
val[++nr] = x;
urm[nr] = lst[c];
lst[c] = nr;
}
void sterge(int x){
if(!apartine(x))
return;
int c = x % K;
int p = lst[c];
if(val[p] == x)
lst[c] = urm[p];
else{
while(urm[p] != 0 && val[urm[p]] != x)
p = urm[p];
if(urm[p] != 0)
urm[p] = urm[urm[p]];
}
}
int main()
{
FILE *fin, *fout;
int n,op,x,i;
fin = fopen("hashuri.in","r");
fout = fopen("hashuri.out","w");
fscanf(fin,"%d",&n);
for(i=0; i<n; i++){
fscanf(fin,"%d %d",&op,&x);
if(op == 1)
adauga(x);
else if(op == 2)
sterge(x);
else
fprintf(fout,"%d\n",apartine(x));
}
fclose(fin);
fclose(fout);
return 0;
}