Pagini recente » Cod sursa (job #1486857) | Cod sursa (job #1454651) | Cod sursa (job #1909676) | Cod sursa (job #1673631) | Cod sursa (job #2588849)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
const int N = 1000005, M = 666019;
int urm[N], lst[N], val[N];
int 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)
{
int c = x % M;
if(apartine(x)){
return;
}
val[++nr] = x;
urm[nr] = lst[c];
lst[c] = nr;
}
void sterge(int x)
{
int c = x % M, 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 n;
in >> n;
while(n--){
int code, x;
in >> code >> x;
if(code == 1)
adauga(x);
else if(code == 2)
sterge(x);
else{
bool a = apartine(x);
if(a == true){
out << 1 << "\n";
}
else{
out << 0 << "\n";
}
}
}
return 0;
}