Pagini recente » Cod sursa (job #579078) | Cod sursa (job #2049356) | Cod sursa (job #2846738) | Cod sursa (job #2829325) | Cod sursa (job #2254479)
#include <fstream>
#include <vector>
using namespace std;
/// hash
const int p = 777013;
vector <int> h[p]; /// hash-ul
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
void Add (int x) /// adauga pe x in hash
{
int r;
r = x % p;
h[r].push_back(x);
}
bool Search (int x) /// cauta pe x in hash
{
int r;
r = x % p;
for (auto v : h[r])
if (v == x)
return true;
return false;
}
void Delete (int x) /// sterge pe x din hash
{
int r, L, i;
r = x % p;
L = h[r].size();
for (i = 0; i < L; i++)
if (x == h[r][i])
{
h[r][i] = h[r][L-1];
h[r].pop_back();
return;
}
}
int main()
{
int n, i, task, x;
fin >> n;
for (i = 1; i <= n; i++)
{
fin >> task >> x;
if (task == 1 && !Search(x))
Add(x);
else if (task == 2)
Delete(x);
else
fout << Search(x) << "\n";
}
fout.close();
return 0;
}