Pagini recente » Cod sursa (job #2276351) | Cod sursa (job #1644007) | Cod sursa (job #966310) | Cod sursa (job #638101) | Cod sursa (job #1523374)
#include <fstream>
using namespace std;
const int nmax = 1000000;
const int p = 666023;
int nr[nmax];
int urm[nmax];
int lst[p];
int cont = 0, l;
bool cauta(int x);
void adauga(int x);
void sterge(int x);
int main(){
ifstream in("hashuri.in");
int n, q;
ofstream out("hashuri.out");
short c;
in >> n;
while (n--){
in >> c >> q;
if (c == 1)
adauga(q);
if (c == 2)
sterge(q);
if (c == 3 && cauta(q))
out << "1\n";
if (c == 3 && !cauta(q))
out << "0\n";
}
in.close();
out.close();
return 0;
}
void sterge(int x){
if (!cauta(x))
return;
l = lst[x % p];
while (nr[l] != x)
l = urm[l];
nr[l] = -1;
}
void adauga(int x){
if (cauta(x))
return;
cont++;
nr[cont] = x;
urm[cont] = lst[x % p];
lst[x % p] = cont;
}
bool cauta(int x){
l = lst[x % p];
while (l != 0){
if (nr[l] == x)
return true;
l = urm[l];
}
return false;
}