Cod sursa(job #2231896)

Utilizator DawlauAndrei Blahovici Dawlau Data 16 august 2018 14:40:39
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

const int Mod = 102653;
vector <int> HashMap[Mod];

inline void Insert(vector <int> HashMap[Mod], const int &x) {

	for (const int &itm : HashMap[x % Mod])
		if (itm == x) return;
	HashMap[x % Mod].push_back(x);
}

inline void Erase(vector <int> HashMap[Mod], const int &x) {

	for(auto it = HashMap[x % Mod].begin(); it != HashMap[x % Mod].end(); ++it)
		if (*it == x) {

			HashMap[x % Mod].erase(it);
			return ;
		}
}

inline bool Search(vector <int> HashMap[Mod], const int &x) {

	for (const int &itm : HashMap[x % Mod])
		if (itm == x)
			return true;
	return false;
}

int main() {

	int Q;
	fin >> Q;

	for (; Q; --Q) {

		int code, x;
		fin >> code >> x;

		if (code == 1)
			Insert(HashMap, x);
		else if (code == 2)
			Erase(HashMap, x);
		else fout << Search(HashMap, x) << '\n';;
	}
}