Pagini recente » Cod sursa (job #2502562) | Cod sursa (job #1440615) | Cod sursa (job #2084338) | Cod sursa (job #570295) | Cod sursa (job #2594613)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
const int N = 1000005, M = 666019;
int val[N], lst[N], urm[N];
int nr;
bool exista(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(exista(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;
switch(code)
{
case 1:
adauga(x);
break;
case 2:
sterge(x);
break;
case 3:
if(exista(x)){
out << 1 << "\n";
}
else{
out << 0 << "\n";
}
break;
}
}
return 0;
}