Pagini recente » Cod sursa (job #1086218) | Cod sursa (job #344642) | Cod sursa (job #437325) | Cod sursa (job #2131473) | Cod sursa (job #2825007)
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <unordered_map>
#include <cstring>
#include <climits>
#define NMAX 1000003
using namespace std;
int n;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
vector<int>v[NMAX];
vector<int>::iterator find_hash(int x,int hash)
{
for (auto itr = v[hash].begin(); itr != v[hash].end(); itr++)
{
if (*itr == x)
{
//deja am rez;
return itr;
}
}
return v[hash].end();
}
void insert_val(int x)
{
int hash = x % NMAX;
//caut in lista de vec a hashului
if (find_hash(x, hash) == v[hash].end())
{
v[hash].push_back(x);
}
}
void delete_val(int x)
{
int hash = x % NMAX;
//caut in lista de vec a hashului
auto itr = find_hash(x, hash);
if ( itr!= v[hash].end())
{
v[hash].erase(itr);
}
}
int main()
{
fin >> n;
for (int i = 1; i <= n; i++)
{
int op;
long long int val;
fin >>op>> val;
if (op == 1)
{
insert_val(val);
}
else if (op == 2)
{
delete_val(val);
}
else {
int hash = val % NMAX;
auto itr = find_hash(val, hash);
bool ok = itr!= v[hash].end();
fout << ok<<"\n";
}
}
return 0;
}