Cod sursa(job #2742782)

Utilizator AlexCrpCarpineanu Alexandru AlexCrp Data 21 aprilie 2021 19:19:46
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.99 kb
#include <iostream>
#include <fstream>
#include <vector>
#define prime 666013
using namespace std;

vector<int> hashh[prime];

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

int getHashValue(int x)
{
	return (x % prime);
}

void add(int x)
{
	int val = getHashValue(x);
	hashh[val].push_back(x);
}

void del(int x)
{
	int val = getHashValue(x);
	for (int i = 0; i < hashh[val].size(); i++)
	{
		if (hashh[val][i] == x)
		{
			hashh[val].erase(hashh[val].begin() + i);
		}
	}
}

bool get(int x)
{
	int val = getHashValue(x);
	for (int i = 0; i < hashh[val].size(); i++)
	{
		if (hashh[val][i] == x)
			return true;
	}
	return false;

}

int main()
{

	int n, op, x;

	fin >> n;

	for (int i = 0; i < n; i++)
	{
		fin >> op >> x;
		if (op == 1)
		{
			add(x);
		}
		else if (op == 2)
		{
			del(x);
		}
		else
		{
			if (get(x))
			{
				fout << 1 << endl;
			}
			else
			{
				fout << 0 << endl;
			}
		}
	}

	return 0;
}