Pagini recente » Cod sursa (job #77769) | Cod sursa (job #2355748) | Cod sursa (job #2777342) | Cod sursa (job #1166444) | Cod sursa (job #3131009)
//#include <iostream>
#include <vector>
#include <fstream>
//using namespace std;
std::ifstream cin("hashuri.in");
std::ofstream cout("hashuri.out");
template<const int size>
class Hash{
std::vector<long long> vals;
std::vector<long long> next;
std::vector<long long> start;
public:
Hash(){vals.resize(1);
next.resize(1);
start.resize(size);
}
void add(long long val){
long long h = val % size;
vals.push_back(val);
next.push_back(start[h]);
start[h] = vals.size() -1;
}
void erase(long long val){
long long h = val % size;
long long poz = start[h];
if(vals[poz] == val){
start[h] = 0;
return;
}
while(next[poz]){
if(vals[next[poz]]==val){
next[poz] = next[next[poz]];
break;
}
poz = next[poz];
}
}
bool find(long long val){
long long h = val % size;
long long poz = start[h];
while(poz){
if(vals[poz]==val){
return true;
}
poz = next[poz];
}
return false;
}
};
int main() {
long long n;
cin>>n;
Hash<666013> hash;
for(long long i=0;i<n;i++){
long long comanda, nr;
cin>>comanda>>nr;
switch (comanda) {
case 1:{hash.add(nr);break;}
case 2:{hash.erase(nr);break;}
case 3:{cout<<hash.find(nr)<<'\n';break;}
default:{}
}
}
return 0;
}