Cod sursa(job #239306)

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

#define HMAX 1<<20
#define HMSK (HMAX-1)
list<int> a[HMAX];
int N, op, x;

int find(int x)
{
	int p = x&HMSK;
	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[x&HMSK].push_back(x);
}

inline void remove(int x)
{
	a[x&HMSK].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;
}