Pagini recente » Cod sursa (job #1310657) | Cod sursa (job #1731897) | Cod sursa (job #1683211) | Cod sursa (job #1877854) | Cod sursa (job #2760774)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
const int prim = 999983;
int n, op, x;
vector<int> Hash[prim];
void adauga(int x)
{
Hash[x % prim].push_back(x);
}
int cauta(int x)
{
for(auto aux : Hash[x % prim])
if(x == aux)
return 1;
return 0;
}
void sterge(int x)
{
for(int i = 0; i < Hash[x % prim].size(); i++)
if(x == Hash[x % prim][i])
{
Hash[x % prim][i] = Hash[x % prim][Hash[x % prim].size() - 1];
Hash[x % prim].pop_back();
return;
}
}
int main()
{
f >> n;
for(int i = 0; i < n; i++)
{
f >> op >> x;
if(op == 1)
if(!cauta(x))
adauga(x);
if(op == 2)
if(cauta(x))
sterge(x);
if(op == 3)
g << cauta(x) << endl;
}
return 0;
}