Cod sursa(job #1587527)

Utilizator kasperDorin Puscasu kasper Data 2 februarie 2016 10:59:30
Problema Hashuri Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.86 kb
#include<fstream>
//#define infile "hashuri.in"
//#define outfile "hashuri.out"
#define MAX 1000005
using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

typedef struct nod {
	int inf;
	nod* next;
}*lista;

int n, op, x;
lista h[MAX];

bool ok(int y)
{
	for (lista j = h[y % MAX]; j!=NULL; j = j->next)
		if (j->inf == y) return 1;
	return 0;
}
void add(lista &a, int inf)
{
	lista q = new nod;
	q->inf = inf;
	q->next = a;
	a = q;
}

int main()
{
	fin >> n;
	for (int i = 1; i <= n; i++)
	{
		fin >> op >> x;
		if (op == 1)
		{	
			if (ok(x) == 0)
				add(h[x % MAX], x);
		}
		if (op == 2)
		{	
			if (ok(x) == 1)
				for (lista j = h[x % MAX]; j != NULL; j = j->next)
					if (j->inf == x)
					{
						j->inf = -1;
					}
		}
		if (op == 3) {
			fout << ok(x) << endl;
		}
	}
	
	return 0;
}