Pagini recente » Cod sursa (job #1500514) | Cod sursa (job #304853) | Cod sursa (job #2751653) | Cod sursa (job #3288314) | Cod sursa (job #1171245)
#include <vector>
#include <stdio.h>
static const int BUCKET_COUNT = 44729;
static const int DOMAIN_SIZE = 2000000000;
typedef std::vector<std::vector<int>> hash_t;
int hash_f(int n) {
return n % BUCKET_COUNT;
}
void add(hash_t& hash, int n) {
int bucket = hash_f(n);
for (auto const& i : hash[bucket]) {
if (i == n) {
return;
}
}
hash[bucket].push_back(n);
}
void remove(hash_t& hash, int n) {
int bucket = hash_f(n);
for (auto i = hash[bucket].begin(); i != hash[bucket].end(); ++i) {
if (*i == n) {
hash[bucket].erase(i);
return;
}
}
}
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(DOMAIN_SIZE / BUCKET_COUNT + 1);
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", 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--;
}
fclose(stdout);
return 0;
}