Cod sursa(job #239305)

Utilizator azotlichidAdrian Vladu azotlichid Data 4 ianuarie 2009 15:40:06
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
using namespace std;

#define HMAX 700001
list<int> a[HMAX];
int N, op, x;

inline int hp(int x)
{
	while (x >= HMAX) x-= HMAX;
	return x;
}

int find(int x)
{
	int p = hp(x);
	for (list<int> :: iterator it = a[p].begin(); it != a[p].end(); it++)
		if (*it == x)
			return 1;
	return 0;
}

inline void add(int x)
{
	if (!find(x)) a[hp(x)].push_back(x);
}

inline void remove(int x)
{
	a[hp(x)].remove(x);
}

int main()
{
	freopen("hashuri.in", "r", stdin);
	freopen("hashuri.out", "w", stdout);
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
	{
		scanf("%d %d", &op, &x);
		if (op == 1)
			add(x);
		else if (op == 2)
			remove(x);
		else
			printf("%d\n", find(x));
	}
	return 0;
}