Cod sursa(job #1757821)

Utilizator ShadereShhhasgash Shadere Data 15 septembrie 2016 22:00:09
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <climits>

#define DIM 100000

std::vector<int> v[DIM];
std::ofstream ofAfisare("hashuri.out");

void DoInsert(int x)
{
	int cheie = x % DIM;
	for (int i = 0; i < v[cheie].size(); ++i)
		if (v[cheie][i] == x)
			return;
	v[cheie].push_back(x);
}

void DoDelete(int x)
{
	int cheie = x % DIM;
	for (int i = 0; i < v[cheie].size(); ++i)
		if (v[cheie][i] == x)
			v[cheie].erase(v[cheie].begin() + i);
}

void DoOutput(int x)
{
	int cheie = x % DIM;
	if (v[cheie].size())
		ofAfisare << "1\n";
	else
		ofAfisare << "0\n";
}

int main()
{
	int N, x, op;
	std::ifstream ifCitire("hashuri.in");
	ifCitire >> N;
	for (int i = 0; i < N; ++i)
	{
		ifCitire >> op >> x;
		if (op == 1) // Insert
			DoInsert(x);
		else if (op == 2)// Delete
			DoDelete(x);
		else if (op == 3)// Output
			DoOutput(x);
	}
}