Cod sursa(job #286371)

Utilizator cotofanaCotofana Cristian cotofana Data 23 martie 2009 19:12:51
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <cstdio>
#include <vector>
#define dim 666999

using namespace std;

int n;
vector<int> hash[dim];

vector<int>::iterator find(int x)
{
	int l=x%dim;
	vector<int>::iterator it;
	for (it=hash[l].begin(); it!=hash[l].end(); it++)
		if (*it==x) return it;
	return hash[l].end();
}

void add(int x)
{
	int l=x%dim;
	if (find(x)==hash[l].end())
		hash[l].push_back(x);
}

void del(int x)
{
	int l=x%dim;
	vector<int>::iterator it=find(x);
	
	if (it!=hash[l].end())
		hash[l].erase(it);
}

int main()
{
	int op, x;
	freopen("hashuri.in", "r", stdin);
	freopen("hashuri.out", "w", stdout);
	scanf("%d\n", &n);
	for (; n; n--)
	{
		scanf("%d %d\n", &op, &x);
		if (op==1) 
		{
			add(x);
			continue;
		}
		if (op==2)
		{
			del(x);
			continue;
		}
		printf("%d\n", find(x)!=hash[x%dim].end());
	}
	return 0;
}