Cod sursa(job #2449944)

Utilizator dorufDoru Floare doruf Data 21 august 2019 11:56:24
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.96 kb
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

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

const int Mod = 666013;
const int notFound = -1;

vector <int> H[Mod];
int n, op, x;

int hashSearch(int number);

int main()
{
	fin >> n;

	for (int i = 1; i <= n; ++i)
	{
		fin >> op >> x;

		int xMod = x % Mod;
		int result = hashSearch(x);

		if (op == 1)
		{
			if (result == notFound)
			{
				H[xMod].push_back(x);
			}
		}

		if (op == 2)
		{
			if (result != notFound)
			{
				swap(H[xMod][result], H[xMod][H[xMod].size() - 1]);
				H[xMod].pop_back();
			}
		}

		if (op == 3)
		{
			fout << (result != notFound) << '\n';
		}
	}

	fin.close();
	fout.close();

	return 0;
}

int hashSearch(int number)
{
	int numberMod = number % Mod;
	for (int i = 0; i < H[numberMod].size(); ++i)
	{
		if (H[numberMod][i] == number)
		{
			return i;
		}
	}
	return notFound;
}