Pagini recente » Cod sursa (job #1491498) | Cod sursa (job #658362) | Cod sursa (job #2613507) | Cod sursa (job #406794) | Cod sursa (job #2567831)
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
const int P = 777013;
vector <int> H[P];
bool InHash (int x)
{
int r = x % P;
for (auto it : H[r])
if (it == x) return true;
return false;
}
void Add (int x)
{
if (!InHash(x))
{
int r = x % P;
H[r].push_back(x);
}
}
void Delete (int x)
{
int r = x % P;
for (int i = 0; i < H[r].size(); i++)
if (H[r][i] == x)
{
swap(H[r][i], H[r][H[r].size() - 1]);
H[r].pop_back();
return;
}
}
void Read ()
{
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
int n;
fin >> n;
while (n--)
{
int op, x;
fin >> op >> x;
if (op == 1) Add(x);
else if (op == 2) Delete(x);
else fout << InHash(x) << "\n";
}
fout.close();
fin.close();
}
int main()
{
Read();
return 0;
}