Cod sursa(job #348347)

Utilizator serbanlupulupulescu serban serbanlupu Data 15 septembrie 2009 15:47:06
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.02 kb
//infoarena
//pb	:	Hashuri

#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

#define PRIM 1000001

vector< vector <int > > H(PRIM);
int n;

bool check(int temp)
{
	vector<int >::iterator it;
	for (it=H[temp%PRIM].begin(); it<H[temp%PRIM].end(); it++)
		if (*it == temp)
			return 1;
	return 0;
}

void del(int temp)
{
	int nr_h=H[temp%PRIM].size()-1;
	int i;
	for (i=0; i<=nr_h; ++i)
		if (H[temp%PRIM][i]==temp)
			break;
	for ( ; i<nr_h; ++i)
		H[temp%PRIM][i]=H[temp%PRIM][i+1];

	H[temp%PRIM].pop_back();
}

void solve()
{
	fstream f("hashuri.in", ios::in);	
	fstream g("hashuri.out", ios::out);

	int dec;
	int temp;

	f>>n;

	for (int i=1; i<=n; ++i)
	{		
		f>>dec;
		if (dec == 1)
		{
			f>>temp;
			if (check(temp) == 0)
				H[temp%PRIM].push_back(temp);
		}
		if (dec == 2)
		{
			f>>temp;
			del(temp);
		}
		if (dec == 3)
		{
			f>>temp;
			g<<check(temp)<<"\n";
		}
	}
	f.close();
	g.close();
}

int main()
{
	solve();
	return 0;
}