Pagini recente » Cod sursa (job #2343310) | Cod sursa (job #3261021) | Cod sursa (job #3146245) | Cod sursa (job #2771820) | Cod sursa (job #919542)
Cod sursa(job #919542)
#include <cstdio>
#include <list>
using namespace std;
const int P = 599993;
list<int> hash_set[P];
inline int hash(int n)
{
return n % P;
}
bool contains(int n)
{
int h = hash(n);
list<int>::iterator it;
for (it = hash_set[h].begin(); it != hash_set[h].end(); ++it)
if (*it == n)
return true;
return false;
}
void remove(int n)
{
int h = hash(n);
list<int>::iterator it;
for (it = hash_set[h].begin(); it != hash_set[h].end(); ++it)
if (*it == n) {
hash_set[h].erase(it);
break;
}
}
void add(int n)
{
int h = hash(n);
list<int>::iterator it;
for (it = hash_set[h].begin(); it != hash_set[h].end(); ++it)
if (*it == n)
return;
hash_set[h].push_back(n);
}
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) {
add(x);
} else if (op == 2) {
remove(x);
} else {
printf("%d\n", contains(x));
}
}
return 0;
}