Cod sursa(job #1413254)

Utilizator CosminRusuCosmin Rusu CosminRusu Data 1 aprilie 2015 19:16:11
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.17 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <unordered_set>

using namespace std;

const int maxn = 1000005;
const int mod = 666013;

int n;
vector <int> g[mod];

inline void solve_unordered_set() {
	ifstream fin("hashuri.in");
	ofstream fout("hashuri.out");
	unordered_set<int> _hash;
	fin >> n;
	while(n -- ) {
		int op, x;
		fin >> op >> x;
		if(op == 1) {
			_hash.insert(x);
		}
		if(op == 2) {
			_hash.erase(x);
		}
		if(op == 3)
			fout << (_hash.find(x) != _hash.end()) << "\n";
	}
}

inline bool find(int x) {
	for(auto it : g[x % mod])
		if(it == x)
			return 1;
	return 0;
}

inline void insert(int x) {
	if(find(x))
		return;
	g[x % mod].push_back(x);
}

inline void erase(int x) {
	if(!find(x))
		return ;
	for(vector <int> :: iterator it = g[x % mod].begin() ; it != g[x % mod].end() ; ++ it)
		if(*it == x) {
			g[x % mod].erase(it);
			return ;
		}
}

inline void solve_vector() {
	ifstream fin("hashuri.in");
	ofstream fout("hashuri.out");
	fin >> n;
	while(n -- ) {
		int op, x;
		fin >> op >> x;
		if(op == 1)
			insert(x);
		if(op == 2)
			erase(x);
		if(op == 3)
			fout << find(x) << '\n';
	}
}

int main() {
	//solve_unordered_set();
	solve_vector();

}