Cod sursa(job #1256003)

Utilizator MarronMarron Marron Data 5 noiembrie 2014 17:59:33
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include <iostream>
#include <fstream>
#include <set>


const int MOD = 1024;
class Hash {
private:
	std::set<int> a[MOD];

public:
	Hash() {
	}

	void insert(int x) {
		int id = x % MOD;
		a[id].insert(x);
	}
	void erase(int x) {
		int id = x % MOD;
		if (a[id].find(x) != a[id].end()) {
			a[id].erase(a[id].find(x));
		}
	}
	bool has(int x) {
		int id = x % MOD;
		if (a[id].find(x) != a[id].end()) {
			return true;
		}
		return false;
	}
};


std::ifstream f("hashuri.in");
std::ofstream g("hashuri.out");


Hash hash;


int main()
{
	int n;
	f >> n;
	for (int i = 1; i <= n; i++) {
		int op, x;
		f >> op >> x;

		if (op == 1) hash.insert(x);
		if (op == 2) hash.erase(x);
		if (op == 3) g << hash.has(x) << '\n';
	}

	
	f.close();
	g.close();
	return 0;
}