Cod sursa(job #2575121)

Utilizator ardutgamerAndrei Bancila ardutgamer Data 6 martie 2020 11:45:09
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.17 kb
#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;
	return (lower_bound(hash[r].begin(), hash[r].end(), val) != hash[r].end());
}

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;
}