Cod sursa(job #2624327)

Utilizator anayepAna-Maria Ungureanu anayep Data 4 iunie 2020 18:27:09
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>
using namespace std;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
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(){
	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();
}