Pagini recente » Cod sursa (job #907863) | Cod sursa (job #2216538) | Cod sursa (job #43966) | Cod sursa (job #2584829) | Cod sursa (job #643084)
Cod sursa(job #643084)
#include <iostream>
#include <fstream>
#include <vector>
#define M 666667
using namespace std;
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);
vector<int>::iterator it = find(x);
if (it == 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()
{
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
int N, op, x;
for (scanf("%d", &N); N; --N)
{
scanf("%d %d", &op, &x);
if (op == 1) // inserare
{
insert(x);
continue;
}
if (op == 2) // stergere
{
del(x);
continue;
}
printf("%d\n", find(x) != hash[hashFunc(x)].end());
}
return 0;
}