Pagini recente » Cod sursa (job #1878136) | Cod sursa (job #509769) | Cod sursa (job #1032238) | Cod sursa (job #2331663) | Cod sursa (job #2533620)
#include <bits/stdc++.h>
const double A = 0.618034;
template <int M>
class HashSet {
public:
HashSet() {}
void insert(int value) {
int v = hash(value), idx = 0;
while (table[v][idx]) {
if (table[v][idx] == value) return;
++ idx;
} table[v][idx] = value;
}
void erase(int value) {
int v = hash(value), idx = 0;
while (table[v][idx]) {
if (table[v][idx] == value) while (table[v][idx]) table[v][idx] = table[v][idx+1], ++ idx;
++ idx;
}
}
bool contains(int value) {
int v = hash(value), idx = 0;
while (table[v][idx]) {
if (table[v][idx] == value) return true;
++ idx;
} return false;
}
private:
int table[M][8];
inline int hash(int x) { return M*(A*x - int(A*x)); }
}; HashSet <666013> set;
std::ifstream input ("hashuri.in");
std::ofstream output("hashuri.out");
int main()
{
int Q; input >> Q;
int op, x;
while (Q--) {
input >> op >> x;
if (op == 1) set.insert(x);
else if (op == 2) set.erase(x);
else if (op == 3) output << set.contains(x) << '\n';
}
return 0;
}