Cod sursa(job #1043151)

Utilizator vld7Campeanu Vlad vld7 Data 28 noiembrie 2013 01:43:38
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include <fstream>
#include <vector>

using namespace std;

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

const int MOD = 666013;

int N;
vector <int> Hash[MOD];

bool find (int value) {
	int list = value % MOD;
	
	for (vector <int> :: iterator it = Hash[list].begin(); it != Hash[list].end(); ++it)
		if (*it == value)
			return 1;
	
	return 0;
}

void insert (int value) {
	int list = value % MOD;
	
	Hash[list].push_back (value);
}

void erase (int value) {
	int list = value % MOD;
	
	for (vector <int> :: iterator it = Hash[list].begin(); it != Hash[list].end(); ++it)
		if (*it == value) {
			Hash[list].erase (it);
			return;
		}
}

int main() {
	f >> N;
	for (int i = 1; i <= N; i++) {
		int op, val;
		f >> op >> val;
		if (op == 1) {
			if (!find (val))
				insert (val);
		} else if (op == 2)
			erase (val);
		else
			g << find (val) << '\n';
	}
	
	return 0;
}