Cod sursa(job #2750815)

Utilizator vladalex420@gmail.comLuta Vlad Alexandru [email protected] Data 13 mai 2021 12:26:40
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.49 kb
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <utility>
#include <vector>
#include <unordered_map>
#include <algorithm>

#include <fstream>
#include <stdio.h>

#include <iostream>
#include <list>

struct HashMap
{
	static constexpr int P = 666013; //a big prime number

	std::vector<int> elements[P];

	void addElement(int el)
	{
		int index = el % P;
		if (std::find(elements[index].begin(), elements[index].end(), el) == elements[index].end())
		{
			elements[index].push_back(el);
		}
		//elements[index].insert(el);
	}

	void removeElement(int el)
	{
		int index = el % P;
		auto f = std::find(elements[index].begin(), elements[index].end(), el);
		if (f != elements[index].end())
		{
			elements[index].erase(f);
		}
	}

	int isElement(int el)
	{
		int index = el % P;
		if (std::find(elements[index].begin(), elements[index].end(), el) != elements[index].end())
		{
			return 1;
		}
		else
		{
			return 0;
		};

	}

};


int main()
{

	std::ifstream in("hashuri.in");
	std::ofstream out("hashuri.out");

	if (!in.is_open())
	{
		return 0;
	}

	HashMap hashMap;

	int n = 0;
	in >> n;

	for (int i = 0; i < n; i++)
	{
		int op, val;
		in >> op >> val;

		if (op == 1)
		{
			hashMap.addElement(val);
		}
		else
			if (op == 2)
			{
				hashMap.removeElement(val);
			}
			else
				if (op == 3)
				{
					out << hashMap.isElement(val) << "\n";
				}

	}

	in.close();
	out.close();

	return 0;
}