Pagini recente » Cod sursa (job #96242) | Cod sursa (job #2984635) | Cod sursa (job #223170) | Cod sursa (job #1001620) | Cod sursa (job #1559251)
// Hashuri
#include <fstream>
#include <vector>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
const int P = 666013;//o valoare care are in jur de 2 coliziuni, mai mare doar ocupa memorie
vector<int> h[P];
bool exista(int x)
{
int i = x % P;
for (unsigned int j = 0;j < h[i].size();++j)
if (h[i][j] == x)
return true;
return false;
}
void adauga(int x)
{
if (exista(x))
return;
h[x % P].push_back(x);
}
void scoate(int x)
{
if (!exista(x))
return;
int i = x % P;
int j = 0;
while(h[i][j] != x)
++j;
h[i].erase(h[i].begin() + j);
}
int main()
{
int n;
int tip, x;
in >> n;
for (int i = 1;i <= n;++i)
{
in >> tip >> x;
if (tip == 1)
adauga(x);
if (tip == 2)
scoate(x);
if (tip == 3)
out << exista(x) << '\n';
}
return 0;
}