Pagini recente » Cod sursa (job #1867064) | Cod sursa (job #2488848) | Cod sursa (job #2615764) | Cod sursa (job #354673) | Cod sursa (job #1279606)
#include <cstdio>
#include <vector>
using namespace std;
const char IN_FILE[] = "hashuri.in";
const char OUT_FILE[] = "hashuri.out";
struct Hash {
private:
const int MOD = 69001;
vector<int> v[69001];
public:
bool insert(const int key) {
int hash_key = key % this->MOD;
if (!this->search(key)) {
for (auto &it: this->v[hash_key]) {
if (it == -1) {
it = key;
return true;
}
}
this->v[hash_key].push_back(key);
return true;
}
return false;
}
bool erase(const int key) {
int hash_key = key % this->MOD;
for (auto &it: this->v[hash_key]) {
if (it == key) {
it = -1;
return true;
}
}
return false;
}
bool search(const int key) {
int hash_key = key % this->MOD;
for (auto it: this->v[hash_key]) {
if (it == key) {
return true;
}
}
return false;
}
};
int main() {
freopen(IN_FILE, "r", stdin);
freopen(OUT_FILE, "w", stdout);
int N; scanf("%d", &N);
Hash A;
int op, key;
while (N--) {
scanf("%d%d", &op, &key);
switch (op) {
case 1:
A.insert(key);
break;
case 2:
A.erase(key);
break;
case 3:
printf("%d\n", A.search(key));
break;
}
}
return 0;
}