Pagini recente » Cod sursa (job #136179) | Cod sursa (job #1230329) | Cod sursa (job #2246503) | Cod sursa (job #1939963) | Cod sursa (job #948210)
Cod sursa(job #948210)
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
using namespace std;
class Hash {
public:
Hash() {}
void Insert(const int value) {
int key = GetKey(value);
if (!Search(value))
table[key].push_back(value);
}
void Erase(const int value) {
int key = GetKey(value);
for (vector<int>::iterator v = table[key].begin(); v != table[key].end(); ++v) {
if (*v == value) {
table[key].erase(v);
return;
}
}
}
bool Search(const int value) {
int key = GetKey(value);
for (vector<int>::iterator v = table[key].begin(); v != table[key].end(); ++v)
if (*v == value)
return true;
return false;
}
private:
static const int U = 666013;
vector<int> table[U];
static int GetKey(const int value) {
return value % U;
}
};
Hash H;
int main() {
assert(freopen("hashuri.in", "r", stdin));
assert(freopen("hashuri.out", "w", stdout));
int N; assert(scanf("%d", &N) == 1);
for (; N > 0; --N) {
int Type, X; assert(scanf("%d %d", &Type, &X) == 2);
if (Type == 1)
H.Insert(X);
if (Type == 2)
H.Erase(X);
if (Type == 3)
printf("%d\n", H.Search(X));
}
return 0;
}