Cod sursa(job #944446)

Utilizator howsiweiHow Si Wei howsiwei Data 28 aprilie 2013 16:25:22
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <forward_list>
#include <vector>
using namespace std;

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

	void insert( int x ) {
		int r = x % mod;
		if ( find( table[r].begin(), table[r].end(), x ) == table[r].end() ) {
			table[r].push_front(x);
		}
	}

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

	bool inSet( int x ) {
		int r = x % mod;
		return find( table[r].begin(), table[r].end(), x ) != table[r].end();
	}

private:
	static const  int mod = 666013;
	vector<forward_list<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;
}