Pagini recente » Cod sursa (job #1953417) | Cod sursa (job #274051) | Cod sursa (job #709069) | Cod sursa (job #2364562) | Cod sursa (job #1799798)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
class Hash {
public:
void insert(const int value) {
const int key = getKey(value);
if (find(value) == table[key].end()) {
table[key].push_back(value);
}
}
void erase(const int value) {
const int key = getKey(value);
table[key].erase(find(value));
}
bool contains(const int value) const {
const int key = getKey(value);
return find(value) != table[key].end();
}
private:
static const int U = 666013;
static int getKey(const int value) {
return (value % U + U) % U;
}
vector<int>::const_iterator find(const int value) const {
return find(table[key].begin(), table[key].end(), value);
}
vector<int> table[U];
};
int main() {
ifstream in("hashuri.in");
ofstream out"(hashuri.out");
int q;
in >> q;
Hash hash;
for (; q > 0; --q) {
int op, x;
in >> op >> x;
if (op == 1) {
hash.insert(x);
} else if (op == 2) {
hash.erase(x);
} else if (op == 3) {
out << (hash.contains(x) ? 1 : 0) << "\n";
}
}
in.close();
out.close();
return 0;
}