Pagini recente » Cod sursa (job #1582029) | Cod sursa (job #1844853) | Cod sursa (job #2014222) | Cod sursa (job #2397592) | Cod sursa (job #1279591)
#include <cstdio>
#include <vector>
using namespace std;
const char IN_FILE[] = "hashuri.in";
const char OUT_FILE[] = "hashuri.out";
struct Hash {
const int MOD = 69001;
vector<int> v[69001];
int insert(const int key) {
int hash_key = key % this->MOD;
this->v[hash_key].push_back(key);
return hash_key;
}
bool erase(const int key) {
int hash_key = key % this->MOD;
for (auto it = this->v[hash_key].begin(); it != this->v[hash_key].end(); it++) {
if (*it == key) {
this->v[hash_key].erase(it);
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;
}