Cod sursa(job #1799793)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 6 noiembrie 2016 20:01:44
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.99 kb
#include <fstream>
#include <vector>

using namespace std;

class Hash {
 public:
	void insert(const int value) {
		const int key = getKey(value);
		if (table[key].find(value) == table[key].end()) {
			table[key].push_back(value);
		}
	}


	void erase(const int value) {
		const int key = getKey(value);
		table[key].erase(value);
	}


	bool contains(const int value) const {
		const int key = getKey(value);
		return table[key].find(value) != table[key].end();
	}


 private:
	static const int U = 666013;


	static int getKey(const int value) {
		return (value % U + U) % U;
	}


	vector<int> table[U];
};

int main() {
	ifstream in("hashuri.in");
	ofstream out"(hashuri.out");
	int q;
	in >> q;
	Hash hash;
	for (; q > 0; --q) {
		int op, x;
		in >> op >> x;
		if (op == 1) {
			hash.insert(x);
		} else if (op == 2) {
			hash.erase(x);
		} else if (op == 3) {
			out << (hash.contains(x) ? 1 : 0) << "\n";
		}
	}
	in.close();
	out.close();
	return 0;
}