Cod sursa(job #2890003)

Utilizator widzAndrei-Daniel Tava widz Data 14 aprilie 2022 08:55:41
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <fstream>
#include <iostream>
#include <vector>
#include <list>

using namespace std;


class EasyHash
{
private:
	vector<list<long long>> storage;
public:
	EasyHash() : storage(834941) {};
	long long& operator[](const long long& nr)
	{
		long long index = nr % 834941;
		for(auto& el : storage[index])
		{
			if (el == nr)
				return el;
		}
		storage[index].emplace_front(0);
		return storage[index].front();
	}
};

int main()
{
	ifstream in("hashuri.in");
	ofstream out("hashuri.out");
	EasyHash set;
	int operations;
	long long parameter;
	short command;
	in >> operations;
	for(int i=0;i<operations;++i)
	{
		in >> command >> parameter;
		switch(command)
		{
		case 1:
			set[parameter] = parameter;
			break;
		case 2:
			set[parameter] = 0;
			break;
		case 3:
			out <<( (set[parameter] != 0) ? 1 : 0 )<< "\n";

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

	
}