Pagini recente » Cod sursa (job #1237650) | Cod sursa (job #1703964) | Cod sursa (job #858531) | Cod sursa (job #1541954) | Cod sursa (job #643080)
Cod sursa(job #643080)
#include <iostream>
#include <fstream>
#include <vector>
#define M 666667
using namespace std;
vector<int> hash[M];
int hashFunc(int x)
{
return x % M;
}
int find(int x)
{
int poz = hashFunc(x);
int listSize = hash[poz].size();
if (listSize > 0)
{
for (unsigned int i = 0; i < listSize; i++)
{
if (hash[poz][i] == x)
{
return i;
}
}
}
return -1;
}
void insert(int x)
{
int poz = hashFunc(x);
int pozL = find(x);
if (pozL == -1)
{
hash[poz].push_back(x);
}
}
void del(int x)
{
int poz = hashFunc(x);
int pozL = find(x);
if (pozL != -1)
{
hash[poz].erase(hash[poz].begin() + pozL);
}
}
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) != -1);
}
return 0;
}