Cod sursa(job #2147702)

Utilizator dorin31Geman Dorin Andrei dorin31 Data 28 februarie 2018 21:59:45
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <vector>
#define modP 66013

using namespace std;

vector <int> H[modP];

inline vector<int>::iterator hashFindValue(int x) {
	int list = x % modP;
	for (vector<int>::iterator it = H[list].begin() ; it != H[list].end() ; ++it)
		if (*it == x)
			return it;
	return H[list].end();
}

void hashInsertValue(int x) {
	int list = x % modP;
	if (hashFindValue(x) == H[list].end())
		H[list].push_back(x);
}

void hashDeleteValue(int x) {
	vector<int>::iterator it;
	int list = x % modP;
	it = hashFindValue(x);
	if (it != H[list].end())
		H[list].erase(it);
}

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

	int N, op, x;
	fin>>N;
	while (N--) {
		fin >> op >> x;
		if (op == 1)
			hashInsertValue(x);
		else if (op == 2)
			hashDeleteValue(x);
		else if (op == 3) {
			vector<int>::iterator it = hashFindValue(x);
			it != H[x % modP].end() ? fout << "1\n" : fout << "0\n";
		}
	}

	return 0;
}