Cod sursa(job #1438216)

Utilizator R4DIC4LTeodorescu Oana Maria R4DIC4L Data 19 mai 2015 13:08:00
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.2 kb
#include <stdio.h>
#include <vector>
#define MOD 666013
using namespace std;

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

int n, op, val;
vector<int> h[MOD];

vector<int>::iterator find_it(int key, int value)
{
	for (auto it = h[key].begin(); it != h[key].end(); ++it)
	{
		if (*it == value)
		{
			return it;
		}
	}

	return h[key].end();
}

bool find(int value)
{
	int key = value % MOD;

	return find_it(key, value) != h[key].end();
}

void insert(int value)
{
	int key = value % MOD;

	if (!find(value))
	{
		h[key].push_back(value);
	}
}

void remove(int value)
{
	int key = value % MOD;

	auto pos = find_it(key, value);
	if (pos != h[key].end())
	{
		h[key].erase(pos);
	}
}

int main()
{
	freopen("hashuri.in", "r", stdin);
	freopen("hashuri.out", "w", stdout);

	//in >> n;
	scanf("%d", &n);
	while (n--)
	{
		//in >> op >> val;
		scanf("%d%d", &op, &val);
		if (op == 1)
		{
			insert(val);
		}
		else
		{
			if (op == 2)
			{
				remove(val);
			}
			else
			{
				//out << find(val) << "\n";
				if (find(val))
				{
					printf("1\n");
				}
				else
				{
					printf("0\n");
				}
			}
		}
	}
	return 0;
}