Cod sursa(job #1039623)

Utilizator TwoOfDiamondsDaniel Alexandru Radu TwoOfDiamonds Data 23 noiembrie 2013 12:42:12
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.21 kb
#include <fstream>
#include <iostream>
#include <vector>

#define PRIME 666013

using namespace std;

void op1(vector<int> *vec, int x)
{
	if (!vec[x%PRIME].empty())
	{
		for (vector<int>::const_iterator it = vec[x%PRIME].begin(); it != vec[x%PRIME].end(); it++)
		{
			if (*it == x)
			{
				return;
			}
		}
	}
	vec[x%PRIME].push_back(x);
}

void op2(vector<int> *vec, int x)
{
	if (vec[x%PRIME].empty())
		return;

	for (vector<int>::iterator it = vec[x%PRIME].begin(); it != vec[x%PRIME].end(); it++)
	{
		if (*it == x)
		{
			vec[x%PRIME].erase(it);
			return;
		}
	}
}

int op3(vector<int>* vec, int x)
{

	if (vec[x%PRIME].empty())
		return 0;

	for (vector<int>::const_iterator it = vec[x%PRIME].begin(); it != vec[x%PRIME].end(); it++)
	{
		if (*it == x)
		{
			return 1;
		}
	}

	return 0;
}

int main()
{
	ifstream IN("hashuri.in");
	ofstream OUT("hashuri.out");

	vector<int> *Map = new vector<int>[PRIME];

	int n; IN >> n;


	for (int i = 0; i < n; i++)
	{
		int op; IN >> op;
		int num; IN >> num;

		if (op == 1)
			op1(Map, num);
		else if (op == 2)
			op2(Map, num);
		else if (op == 3)
			OUT << op3(Map, num) << "\n";

	}

	return 0;
}