Cod sursa(job #2741753)

Utilizator vladalex420@gmail.comLuta Vlad Alexandru [email protected] Data 18 aprilie 2021 18:15:01
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.15 kb
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <utility>
#include <vector>
#include <unordered_map>

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

#include <iostream>
#include <set>

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

	std::set<int> elements[P];
	
	void addElement(int el)
	{
		int index = el % P;
		elements[index].insert(el);
	}
	
	void removeElement(int el)
	{
		int index = el % P;
		elements[index].erase(el);
	}

	int isElement(int el)
	{
		int index = el % P;
		if (elements[index].find(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;
}