Pagini recente » Cod sursa (job #666597) | Cod sursa (job #2190877) | Cod sursa (job #1619257) | Cod sursa (job #462700) | Cod sursa (job #644522)
Cod sursa(job #644522)
#include <stdio.h>
#include <vector>
using namespace std;
#define M 800000
int N;
vector<int> hash[M];
int hashFunc(int x)
{
return x % M;
}
vector<int>::iterator find(int x)
{
int poz = hashFunc(x);
vector<int>::iterator it;
for (it = hash[poz].begin(); it != hash[poz].end(); ++it)
if (*it == x)
return it;
return hash[poz].end();
}
void insert(int x)
{
int poz = hashFunc(x);
if (find(x) == hash[poz].end())
hash[poz].push_back(x);
}
void del(int x)
{
int poz = hashFunc(x);
vector<int>::iterator it = find(x);
if (it != hash[poz].end())
hash[poz].erase(it);
}
int main()
{
int op, x;
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
scanf("%d", &N);
while (N > 0)
{
scanf("%d %d", &op, &x);
if (op == 1) // inserare
{
insert(x);
} else if (op == 2) // stergere
{
del(x);
} else if (op == 3)
{
printf("%d\n", find(x) != hash[hashFunc(x)].end());
}
N--;
}
return 0;
}