Pagini recente » Cod sursa (job #3151420) | Cod sursa (job #2745304) | Cod sursa (job #2879337) | Cod sursa (job #2527308) | Cod sursa (job #2586267)
#include <iostream>
#include <fstream>
const int N = 1000001;
const int M = 666019;
std::ifstream in("hashuri.in");
std::ofstream out("hashuri.out");
int val[N],urm[N],lst[N],nr;
bool apartine(int x){
int c=x%M;
int p=lst[c];
while(p!=0){
if(val[p]==x)
return 1;
p=urm[p];
}
return 0;
}
void adauga(int x){
if(apartine(x))
return;
int c=x%M;
val[++nr]=x;
urm[nr]=lst[c];
lst[c]=nr;
}
void sterge(int x){
int c=x%M;
int 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 t;
in>>t;
while(t){
t--;
int op,x;
in>>op>>x;
if(op==1)
adauga(x);
else
if(op==3)
out<<apartine(x)<<'\n';
else
sterge(x);
}
return 0;
}