Pagini recente » Cod sursa (job #2226354) | Cod sursa (job #2321463) | Cod sursa (job #564092) | Cod sursa (job #1883051) | Cod sursa (job #1611621)
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#define MOD 2000001
using namespace std;
struct Elem {
int value;
Elem* next;
};
Elem* hashmap[MOD];
Elem* find(int value) {
Elem* curr = hashmap[value % MOD];
while (curr) {
if (curr->value == value) break;
curr = curr->next;
}
return curr;
}
void remove(int value) {
Elem* curr = hashmap[value % MOD];
Elem* prev = 0;
while (curr) {
if (curr->value == value) break;
prev = curr;
curr = curr->next;
}
if (curr) {
if (prev) prev->next = curr->next;
else hashmap[value % MOD] = curr->next;
delete curr;
}
}
void insert(int value) {
Elem* curr = hashmap[value % MOD];
Elem* newValue = new Elem;
newValue->value = value;
hashmap[value % MOD] = newValue;
if (curr) newValue->next = curr;
else newValue->next = 0;
}
int main() {
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
int n;
scanf("%d", &n);
for(int i=0; i < n; ++i) {
int op, x;
scanf("%d %d", &op, &x);
if (op == 1) {
insert(x);
} else if (op == 2) {
remove(x);
} else {
Elem* el = find(x);
if (el) printf("1\n");
else printf("0\n");
}
}
}