Cod sursa(job #1455757)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 29 iunie 2015 00:45:36
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <vector>
#include <list>
#include <fstream>
#include <algorithm>
using namespace std;

constexpr int table_sz = 1426231;

class myhash{
	vector<list<long long> > buckete;
public:
	myhash(bool):
		buckete(table_sz){}
	void erase(const long long x){
		auto& buc = buckete[x%table_sz];
		auto it = find(begin(buc), end(buc), x);
		if(it != end(buc)){
			buc.erase(it); } }
	bool _find(const long long x){
		const auto& buc = buckete[x%table_sz];
		return find(begin(buc), end(buc), x) !=
			end(buc); }
	void insert(const long long x){
		if(!_find(x)){
			buckete[x%table_sz].push_back(x); } } };

int main(){
	ifstream f("hashuri.in");
	ofstream g("hashuri.out");
	int n;
	f >> n;
	int tip;
	long long val;
	myhash hs(true);
	for(int i = 0; i < n; ++i){
		f >> tip >> val;
		switch(tip){
		case 1:
			hs.insert(val);
			break;
		case 2:
			hs.erase(val);
			break;
		case 3:
			g << hs._find(val) << '\n';
			break; } }
	return 0; }