Cod sursa(job #2552334)

Utilizator arckerDolteanu Gabriel arcker Data 20 februarie 2020 19:25:25
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <bits/stdc++.h>
using namespace std;
 
const int MOD = 666013;
 
vector<pair<int, bool> > H[MOD];
 
void add(int x){
	int key = x % MOD;
	for(auto &c: H[key])
		if(c.first == x)
			return;
	H[key].push_back({x, 1});
}
 
void del(int x){
	int key = x % MOD;
	for(auto &c: H[key])
		if(c.first == x)
			c.second = 0;
}
 
bool present(int x){
	int key = x % MOD;
	for(auto &c: H[key])
		if(c.first == x && c.second)
			return 1;
	return 0;
}
 
int main(){
	ifstream cin("hashuri.in");
	ofstream cout("hashuri.out");
	int op, x, n;
	cin >> n;
	for(int i = 1; i <= n; ++i){
		cin >> op >> x;
		if(op == 1)
			add(x);
		else if(op == 2)
			del(x);
		else
			cout << present(x) << '\n';
	}
	cin.close(), cout.close();
}