Cod sursa(job #2825007)

Utilizator TudosieRazvanTudosie Marius-Razvan TudosieRazvan Data 3 ianuarie 2022 20:37:38
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.22 kb
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <unordered_map>
#include <cstring>
#include <climits>

#define NMAX 1000003
using namespace std;

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


vector<int>v[NMAX];

vector<int>::iterator find_hash(int x,int hash)
{
	for (auto itr = v[hash].begin(); itr != v[hash].end(); itr++)
	{
		if (*itr == x)
		{
			//deja am rez;
			return itr;
		}
	}
	return  v[hash].end();
}

void insert_val(int x)
{
	int hash = x % NMAX;
	//caut in lista de vec a hashului
	if (find_hash(x, hash) == v[hash].end())
	{
		v[hash].push_back(x);
	}
}

void delete_val(int x)
{
	int hash = x % NMAX;
	//caut in lista de vec a hashului
	auto itr = find_hash(x, hash);
	if ( itr!= v[hash].end())
	{
		v[hash].erase(itr);
	}
}

int main()
{
	fin >> n;

	
	for (int i = 1; i <= n; i++)
	{
		int op;
		long long int val;
		fin >>op>> val;
		if (op == 1)
		{
			insert_val(val);
		}
		else if (op == 2)
		{
			delete_val(val);
		}
		else {
			int hash = val % NMAX;
			auto itr = find_hash(val, hash);
			bool ok = itr!= v[hash].end();
			fout << ok<<"\n";
		}
		
	}
	
	return 0;
}