Cod sursa(job #442116)

Utilizator ChallengeMurtaza Alexandru Challenge Data 13 aprilie 2010 21:32:25
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#include <fstream>
#include <vector>

using namespace std;

const char InFile[]="hashuri.in";
const char OutFile[]="hashuri.out";
const int MOD=666013;

ifstream fin(InFile);
ofstream fout(OutFile);
vector<int> L[MOD];
int n,op,x;

vector<int>::iterator find_value(int x)
{
	int list=x%MOD;
	vector<int>::iterator it;
	for(it=L[list].begin();it!=L[list].end();++it)
	{
		if(*it==x)
		{
			return it;
		}
	}
	return L[list].end();
}

void insert_value(int x)
{
	int list=x%MOD;
	
	if(find_value(x)==L[list].end())
	{
		L[list].push_back(x);
	}
}

void erase_value(int x)
{
	int list=x%MOD;
	vector<int>::iterator it=find_value(x);
	
	if(it!=L[list].end())
	{
		L[list].erase(it);
	}
}

int main()
{
	fin>>n;
	for(int i=1;i<=n;++i)
	{
		fin>>op>>x;
		if(op==1)
		{
			insert_value(x);
		}
		else if(op==2)
		{
			erase_value(x);
		}
		else if(op==3)
		{
			fout<<(int)(find_value(x)!=L[x%MOD].end())<<"\n";
		}
	}
	fin.close();
	fout.close();
	return 0;
}