Cod sursa(job #959897)

Utilizator tudorv96Tudor Varan tudorv96 Data 9 iunie 2013 12:51:07
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <fstream>
#include <vector>
using namespace std;

#define key 666013
#define in "hashuri.in"
#define out "hashuri.out"
#define h(x) ((x)%key)

typedef vector <int> :: iterator IT;

vector <int> list[key];
int n, t, x;

IT search(int x) {
	for (IT it = list[h(x)].begin(); it != list[h(x)].end(); ++it)
		if (*it == x)
			return it;
	return list[h(x)].end();
}

void add(int x) {
	if (search(x) == list[h(x)].end())
		list[h(x)].push_back (x);
}

void erase(int x) {
	IT it = search(x);
	if (it != list[h(x)].end())
		list[h(x)].erase(it);
}

int main() {
	ifstream fin (in);
	fin >> n;
	ofstream fout (out);
	for (int i = 0; i < n; ++i) {
		fin >> t >> x;
		if (t == 1)
			add(x);
		if (t == 2)
			erase(x);
		if (t == 3) {
			IT it = search(x);
			fout << ((it == list[h(x)].end()) ? 0 : 1) << "\n";
		}
	}
	fcloseall();
	return 0;
}