Pagini recente » Cod sursa (job #3285148) | Cod sursa (job #3260089) | Cod sursa (job #3255352) | Cod sursa (job #715025) | Cod sursa (job #1171241)
#include <vector>
#include <stdio.h>
static const int BUCKET_COUNT = 666013;
typedef std::vector<std::vector<int>> hash_t;
int hash_f(int n) {
return n % BUCKET_COUNT;
}
void add(hash_t& hash, int n) {
hash[hash_f(n)].push_back(n);
}
void remove(hash_t& hash, int n) {
int bucket = hash_f(n);
for (auto& i : hash[bucket]) {
if (i == n) {
i = -1;
}
}
}
bool search(hash_t& hash, int n) {
int bucket = hash_f(n);
for (auto const& i : hash[bucket]) {
if (i == n) {
return true;
}
}
return false;
}
int main() {
hash_t h(BUCKET_COUNT);
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "r", stdout);
int n;
scanf("%d", &n);
while (n) {
int op, arg;
scanf("%d %d\n", &op, &arg);
switch(op) {
case 1:
add(h, arg);
break;
case 2:
remove(h, arg);
break;
case 3:
printf("%d\n", search(h, arg));
break;
}
n--;
}
return 0;
}