Cod sursa(job #448364)

Utilizator radu_voroneanuVoroneanu Radu Stefan radu_voroneanu Data 3 mai 2010 16:48:35
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
#include <stdio.h>
#include <vector>
#define list vector<int>
#define MODULO 666013

using namespace std;

list G[MODULO];
int i,n,x,tip;

inline int f(int x)
{
	return x%MODULO;
}

inline list::iterator find(int x)
{
	list::iterator it;
	int poz = f(x);
	for (it = G[poz].begin(); it!=G[poz].end(); it++)
		if (*it == x)
			break;
	return it;
}

inline void erase(int x)
{
	list::iterator it = find(x);
	if (it != G[f(x)].end())
		G[f(x)].erase(it);
}

inline void add(int x)
{
	if (find(x) == G[f(x)].end())
		G[f(x)].push_back(x);
}

int main()
{
	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	scanf("%d",&n);
	for (i=1; i<=n; i++){
		scanf("%d %d",&tip,&x);
		if (tip==1) add(x);
		if (tip==2) erase(x);
		if (tip==3) printf("%d\n",find(x)!=G[f(x)].end());
	}
	return 0;
}