Pagini recente » Monitorul de evaluare | Cod sursa (job #2230785) | Monitorul de evaluare | Cod sursa (job #1183600) | Cod sursa (job #948206)
Cod sursa(job #948206)
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <set>
using namespace std;
class Hash {
public:
Hash() {}
void Insert(const int value) {
table[GetKey(value)].insert(value);
}
void Erase(const int value) {
table[GetKey(value)].erase(value);
}
bool Search(const int value) {
return table[GetKey(value)].find(value) != table[GetKey(value)].end();
}
private:
static const int U = 666013;
set<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;
}