Pagini recente » Cod sursa (job #1754177) | Cod sursa (job #2549132) | Cod sursa (job #1214027) | Cod sursa (job #2310643) | Cod sursa (job #2371188)
#include <bits/stdc++.h>
#define N 123457
using namespace std;
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
int n;
vector <int> L[N];
/**
Toate functiile de hash intorc un numar intre 0 si
N-1, unde M este dimensiunea maxima a tabelei de
hash. Este recomandat ca N sa fie ales un numar
prim si sa se evite alegerea lui N = 2k.
*/
inline void Adauga(int x)
{
int rest = x % N;
L[rest].push_back(x);
}
inline void Sterge(int x)
{
int rest;
rest = x % N;
for (auto w : L[rest])
if (w == x)
{
w = L[rest].back();
L[rest].pop_back();
return;
}
}
inline bool Cauta(int x)
{
int rest = x % N;
for (auto w : L[rest])
if (w == x)
return 1;
return 0;
}
int main()
{
int i, op, x;
fin >> n;
for (i = 1; i <= n; i++)
{
fin >> op >> x;
if (op == 1) Adauga(x);
else if (op == 2) Sterge(x);
else fout << Cauta(x) << "\n";
}
fin.close();
fout.close();
return 0;
}