Pagini recente » Cod sursa (job #957083) | Cod sursa (job #1719785) | Cod sursa (job #993232) | Cod sursa (job #725530) | Cod sursa (job #797397)
Cod sursa(job #797397)
#include <fstream>
#include <vector>
using namespace std;
const int K = 666013;
struct HashTable{
vector<int> hash[K];
inline int h(int x){
return x % K;
}
bool find(int x){
vector<int>& v = hash[h(x)];
for (vector<int> :: iterator it = v.begin() ; it != v.end() ; it++)
if (*it == x)
return true;
return false;
}
void insert(int x){
if (!find(x))
hash[x % K].push_back(x);
}
void erase(int x){
vector<int>& v = hash[x % K];
for (vector<int> :: iterator it = v.begin() ; it != v.end() ; it++)
if (*it == x){
*it = v.back();
v.pop_back();
return;
}
}
};
HashTable H;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int main(){
int t, q, x;
in >> t;
while (t--){
in >> q >> x;
if (q == 1)
H.insert(x);
if (q == 2)
H.erase(x);
if (q == 3)
out << H.find(x) << "\n";
}
return 0;
}