Pagini recente » Cod sursa (job #657474) | Cod sursa (job #1882616) | Cod sursa (job #1099945) | Cod sursa (job #1328383) | Cod sursa (job #1017870)
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
vector<int> hashu[666013];
int hashFunc (int nr)
{
return nr % 666013;
}
void adaugare (int val)
{
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()
{
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;
}
cin.close();
cout.close();
return 0;
}