Cod sursa(job #1256020)

Utilizator MarronMarron Marron Data 5 noiembrie 2014 18:16:59
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include <iostream>
#include <fstream>
#include <vector>


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

public:
	Hash() {
	}

	void insert(int x) {
		int id = x % MOD;
		a[id].push_back(x);
	}
	void erase(int x) {
		int i = x % MOD;
		for (size_t j = 0; j < a[i].size(); j++) {
			if (a[i][j] == x) {
				a[i].erase(a[i].begin() + j);
				j--;
			}
		}
	}
	bool has(int x) {
		int i = x % MOD;
		for (size_t j = 0; j < a[i].size(); j++) {
			if (a[i][j] == x) {
				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;
}