Pagini recente » Cod sursa (job #943353) | Cod sursa (job #2355861) | Cod sursa (job #1587560) | Razvy | Cod sursa (job #3130239)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
class HashTable {
private:
static const int MOD = 666013;
vector<vector<int>> table;
int n;
bool search(int x) {
int index = x % MOD;
const vector<int> &bucket = table[index];
for (auto value: bucket) {
if (value == x) {
return true;
}
}
return false;
}
void insert(int x) {
if (!search(x)) {
int index = x % MOD;
table[index].push_back(x);
}
}
void remove(int x) {
int index = x % MOD;
vector<int> &bucket = table[index];
for (auto it = bucket.begin(); it != bucket.end(); it++) {
if (*it == x) {
bucket.erase(it);
break;
}
}
}
public:
HashTable() : table(MOD) {}
void start() {
fin >> n;
for (int i = 0; i < n; i++) {
int op, x;
fin >> op >> x;
if (op == 1) {
insert(x);
} else if (op == 2) {
remove(x);
} else {
fout << search(x) << '\n';
}
}
}
};
int main() {
HashTable hashTable;
hashTable.start();
return 0;
}