Cod sursa(job #2742799)

Utilizator AlexCrpCarpineanu Alexandru AlexCrp Data 21 aprilie 2021 20:20:41
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 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");
void add(int x)
{
	hashh[x % prime].push_back(x);
}
void del(int x)
{
	for (int i = 0; i < hashh[x % prime].size(); i++)
	{
		if (hashh[x % prime][i] == x)
		{
			hashh[x % prime][i] = hashh[x % prime][hashh[x % prime].size() - 1];
			hashh[x % prime].pop_back();
			break;
		}
	}
}
bool get(int x)
{
	for (int i = 0; i < hashh[x % prime].size(); i++)
	{
		if (hashh[x % prime][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 << "\n";
			}
			else
			{
				fout << 0 << "\n";
			}
		}
	}
	return 0;
}