Cod sursa(job #675449)

Utilizator AndreiRSStatescu Andrei Rares AndreiRS Data 7 februarie 2012 16:58:30
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <fstream>
#include <list>
using namespace std;

ifstream fi ("hashuri.in");
ofstream fo ("hashuri.out");

const int mod = 882377;
list <int> H[mod+5];
list <int> :: iterator p;

void cauta (int x, int h)
{
	for (p = H[h].begin(); p != H[h].end(); p++)
		if (*p == x)
			return;
	p = H[mod].begin();
}

int main ()
{
	int t, x, n, h;
	
	fi >> n;
	while ( n-- )
	{
		fi >> t >> x;
		h = x % mod;
		if (t == 1)
		{
			cauta (x, h);
			if (p == H[mod].begin())
				H[h].push_back (x); 
		}
		else if (t == 2)
		{
			cauta (x, h);
			if (p != H[mod].begin())
				H[h].erase (p);
		}
		else if (t == 3)
		{
			cauta (x, h);
			fo << (p != H[mod].begin()) << '\n';
		}
	}	
	
	return 0;
}