Pagini recente » Cod sursa (job #1186507) | Cod sursa (job #2097921) | Cod sursa (job #2455115) | Cod sursa (job #3137293) | Cod sursa (job #2575109)
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int mod1 = 666013;
const int mod2 = 777013;
vector<int>hash1[mod1];
vector<int>hash2[mod2];
bool apare(int val, vector<int>hash[], int mod)
{
int r = val % mod;
for (int i = 0; i < hash[r].size(); i++)
if (hash[r][i] == val)
return true;
return false;
}
void adauga(int val, vector<int>hash[], int mod)
{
int r = val % mod;
if (apare(val, hash, mod)) return;
hash[r].push_back(val);
if (hash[r].size() >= 2)
sort(hash[r].begin(), hash[r].end());
}
void sterge(int val, vector<int> hash[], int mod)
{
int r = val % mod;
if (!apare(val, hash, mod)) return;
hash[r].erase(lower_bound(hash[r].begin(), hash[r].end(), val));
}
int main()
{
int t;
fin >> t;
while (t--)
{
int tip, val;
fin >> tip >> val;
if (tip == 1)
{
adauga(val, hash1, mod1);
adauga(val, hash2, mod2);
}
else if (tip == 2)
{
sterge(val, hash1, mod1);
sterge(val, hash2, mod2);
}
else
fout << (apare(val, hash1, mod1) && apare(val, hash2, mod2)) << "\n";
}
return 0;
}