Pagini recente » Cod sursa (job #2098148) | Cod sursa (job #71206) | Cod sursa (job #3187580) | Cod sursa (job #3042165) | Cod sursa (job #644524)
Cod sursa(job #644524)
#include <stdio.h>
#include <vector>
using namespace std;
#define M 666013
int N;
vector<int> hash[M];
inline vector<int>::iterator find_value(int x)
{
int poz = x % M;
vector<int>::iterator it;
for (it = hash[poz].begin(); it != hash[poz].end(); ++it)
if (*it == x)
return it;
return hash[poz].end();
}
inline void insert_value(int x)
{
int poz = x % M;
if (find_value(x) == hash[poz].end())
hash[poz].push_back(x);
}
inline void erase_value(int x)
{
int poz = x % M;
vector<int>::iterator it = find_value(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);
for (scanf("%d", &N); N; --N)
{
scanf("%d %d", &op, &x);
if (op == 1) // inserare
{
insert_value(x);
continue;
}
if (op == 2) // stergere
{
erase_value(x);
continue;
}
printf("%d\n", find_value(x) != hash[x % M].end());
}
return 0;
}