Cod sursa(job #944437)

Utilizator howsiweiHow Si Wei howsiwei Data 28 aprilie 2013 16:01:21
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.75 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

class HashSet {
public:
	HashSet() {
		table.resize(mod);
	}

	void insert( int x ) {
		int r = x % mod;
		table[r].insert(x);
	}

	void remove( int x ) {
		int r = x % mod;
		table[r].erase(x);
	}

	bool inSet( int x ) {
		int r = x % mod;
		return table[r].count(x);
	}

private:
	static const  int mod = 666013;
	vector<set<int> > table;
};

int main() {
	ifstream fin("hashuri.in");
	ofstream fout("hashuri.out");
	int n;
	fin >> n;
	HashSet a;

	for (int i = 0; i < n; ++i) {
		int op, x;
		fin >> op >> x;
		switch (op) {
			case 1: a.insert(x); break;
			case 2: a.remove(x); break;
			case 3: fout << a.inSet(x) << '\n'; break;
		}
	}

	return 0;
}