Pagini recente » Cod sursa (job #2368035) | Cod sursa (job #1990882) | Cod sursa (job #818670) | Cod sursa (job #1223863) | Cod sursa (job #1017874)
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
vector<int> hashu[886381];
int hashFunc (int nr)
{
return nr % 886381;
}
int cauta(int n);
void adaugare (int val)
{
// <----- ce tampenie ------>
if (cauta(val) == 1)
return;
hashu[hashFunc(val)].push_back(val);
}
void stergere (int val)
{
int hashed = hashFunc(val);
for (vector<int>::iterator i = hashu[hashed].begin(); i != hashu[hashed].end(); ++i)
if (*i == val)
{
hashu[hashed].erase(i);
return;
}
}
int cauta(int val)
{
int hashed = hashFunc(val);
for (vector<int>::iterator i = hashu[hashed].begin(); i != hashu[hashed].end(); ++i)
if (*i == val)
return 1;
return 0;
}
int main()
{
freopen ("hashuri.in", "r", stdin);
freopen ("hashuri.out", "w", stdout);
int n; cin >> n;
for (int i = 1; i <= n; ++i)
{
int tipOp, val;
cin >> tipOp >> val;
if (tipOp == 1)
adaugare (val);
if (tipOp == 2)
stergere (val);
if (tipOp == 3)
cout << cauta(val) << endl;
}
return 0;
}