Cod sursa(job #327197)

Utilizator vlad.maneaVlad Manea vlad.manea Data 27 iunie 2009 16:45:53
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;

int *list[1 << 20];
#define P (1000003)

int f(int x)
{
	int m = x % P;
	if (list[m])
		for (int i = 1; i <= list[m][0]; ++i)
			if (list[m][i] == x)
				return 1;
	return 0;
}

void a(int x)
{
	int m = x % P;
	if (!list[m])
	{
		list[m] = (int*) realloc(list[m], sizeof(int));
		list[m][0] = 0;
	}
	if (!f(x))
	{
		list[m][0]++;
		list[m] = (int*) realloc(list[m], sizeof(int)*(list[m][0]+1));
		list[m][list[m][0]] = x;
	}
}

void r(int x)
{
	int m = x % P;
	if (list[m])
		for (int i = 1; i <= list[m][0]; ++i)
			if (list[m][i] == x)
			{
				list[m][i] = 0;
				return;
			}
}

int main()
{
	ifstream fi("hashuri.in");
	ofstream fo("hashuri.out");
	int N, op, x;
	fi >> N;
	while (N--)
	{
		fi >> op >> x;
		if (op == 1)
			a(x);
		if (op == 2)
			r(x);
		if (op == 3)
			fo << f(x) << '\n';
	}
	fi.close();
	fo.close();
	return 0;
}