Pagini recente » Cod sursa (job #2396616) | Cod sursa (job #1980990) | Cod sursa (job #2804519) | Cod sursa (job #267174) | Cod sursa (job #644527)
Cod sursa(job #644527)
#include <stdio.h>
#include <vector>
using namespace std;
#define MOD 666013
int N;
vector<int> hash[MOD];
inline int hashFunc(int x)
{
return x % MOD;
}
inline vector<int>::iterator find_value(int x)
{
int list = hashFunc(x);
vector<int>::iterator it;
for (it = hash[list].begin(); it != hash[list].end(); ++it)
if (*it == x)
return it;
return hash[list].end();
}
inline void insert_value(int x)
{
int list = hashFunc(x);
if (find_value(x) == hash[list].end())
hash[list].push_back(x);
}
inline void erase_value(int x)
{
int list = hashFunc(x);
vector<int>::iterator it = find_value(x);
if (it != hash[list].end())
hash[list].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);
switch (op) // inserare
{
case 1:
insert_value(x); break;
case 2:
erase_value(x); break;
case 3:
printf("%d\n", find_value(x) != hash[x % MOD].end()); break;
}
N--;
}
return 0;
}