Cod sursa(job #2642864)

Utilizator llama27Asd asd llama27 Data 17 august 2020 13:58:06
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.03 kb
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <set>

using namespace std;

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

const int MOD = 999983;//preferably a prime number
vector<int> HashTable[MOD+1];

int HASH(int x)
{
	return x % MOD;
}

void insert(int x)
{
	int pos = HASH(x);
	for (auto const& it : HashTable[pos])
	{
		if (it == x)
			return;
	}
	HashTable[pos].push_back(x);
}

void del(int x)
{
	int pos = HASH(x);
	for (int i = 0; i < HashTable[pos].size(); i++)
	{
		if (HashTable[pos][i] == x)
			HashTable[pos].erase(HashTable[pos].begin() + i);
	}
}

void inTable(int x)
{
	int pos = HASH(x);
	for (auto const& it : HashTable[pos])
	{
		if (it == x)
		{
			out << 1 << '\n'; return;
		}
	}
	out << 0 << '\n';
}

int main()
{
	int n;
	for (in >> n; n--;)
	{
		int op, x;
		in >> op >> x;
		if (op == 1)
			insert(x);
		else
			if (op == 2)
				del(x);
			else
				inTable(x);
	}
}