Pagini recente » Cod sursa (job #1811645) | Cod sursa (job #1096853) | Cod sursa (job #1958159) | Cod sursa (job #3340620) | Cod sursa (job #3319707)
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using pd = pair<double, double>;
using pld = pair<ld, ld>;
// #define LOCAL
#ifdef LOCAL
ifstream cin("input.txt");
ofstream cout("output2.txt");
#else
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
#endif
#define cin ::cin
#define cout ::cout
const int mod = 666'013;
vector<int> lists[mod];
int hash_function(const int nr)
{
return nr % mod;
}
// op 3: check if number is in the set
bool elem_exists(const int nr)
{
const int nr_hash = hash_function(nr);
for (const auto elem : lists[nr_hash])
{
if (nr == elem)
{
return true;
}
}
return false;
}
// op 1: insert number
void insert_nr(const int nr)
{
const int nr_hash = hash_function(nr);
// if we get a number which is already in the set, we just ignore
// this operation basically and continue on
if (elem_exists(nr))
{
return;
}
lists[nr_hash].emplace_back(nr);
}
// op 2: delete number
void delete_nr(const int nr)
{
const int nr_hash = hash_function(nr);
int elem_pos = 0;
for (const auto elem : lists[nr_hash])
{
if (elem == nr)
{
break;
}
++elem_pos;
}
if (elem_pos == (int)lists[nr_hash].size())
{
return;
}
lists[nr_hash].erase(begin(lists[nr_hash]) + elem_pos);
}
int main()
{
int N;
cin >> N;
while (N--)
{
int op, x;
cin >> op >> x;
if (op == 1)
{
insert_nr(x);
}
else if (op == 2)
{
delete_nr(x);
}
else if (op == 3)
{
cout << elem_exists(x) << "\n";
}
}
}