Pagini recente » Cod sursa (job #1103982) | Cod sursa (job #2655224) | Cod sursa (job #1996208) | Cod sursa (job #2567925) | Cod sursa (job #1454149)
#include <iostream>
#include <fstream>
#include <list>
#include <assert.h>
const int MOD = 666013;
const char IN[] = "hashuri.in", OUT[] = "hashuri.out";
using namespace std;
inline int get_key(int e) {
return e % MOD;
}
list<int> hashMap[MOD];
int OP;
inline void map_add(int x) {
int key = get_key(x);
for (auto& it : hashMap[key]) {
if (it == x) return;
}
hashMap[key].push_back(x);
}
inline void map_remove(int x) {
int key = get_key(x);
std::list<int>::iterator it;
for (it = hashMap[key].begin(); it != hashMap[key].end(); ++it) {
if (*it == x) break;
}
if (it == hashMap[key].end()) return;
hashMap[key].erase(it);
}
inline int map_find(int x) {
int key = get_key(x);
for (auto& it : hashMap[key]) {
if (it == x) return true;
}
return false;
}
inline void read_data() {
assert(freopen(IN, "r", stdin));
assert(scanf("%d", &OP));
assert(freopen(OUT, "w", stdout));
for (int i = 1; i <= OP; ++i) {
int o, x;
assert(scanf("%d %d", &o, &x));
switch (o) {
case 1: map_add(x); break;
case 2: map_remove(x); break;
case 3: printf("%d\n", map_find(x)); break;
}
}
fclose(stdin);
fclose(stdout);
}
int main() {
read_data();
return 0;
}