Cod sursa(job #332255)

Utilizator stinkyStinky si Grasa stinky Data 17 iulie 2009 10:26:08
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include<fstream>
#include<vector>

using namespace std;

const int r = (1<<19)+3;

vector<int> h[r];

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

vector<int>::iterator cauta(int x)
{
	int p=x%r;
	vector<int>::iterator it;
	for(it=h[p].begin() ; it!=h[p].end() && (*it!=x) ; ++it);
	return it;
}

void adauga(int x)
{
	int p=x%r;
	vector<int>::iterator it=cauta(x);
	if(it!=h[p].end())
		return;
	h[p].push_back(x);
}

void sterge(int x)
{
	int p=x%r;
	vector<int>::iterator it=cauta(x);
	if(it==h[p].end())
		return;
	h[p].erase(it);
}

int este(int x)
{
	return (cauta(x) == h[x%r].end() ? 0 : 1);
}

int main()
{
	int n,op,x;
	in>>n;
	while(n--)
	{
		in>>op>>x;
		if(op==1)
			adauga(x);
		if(op==2)
			sterge(x);
		if(op==3)
			out<<este(x)<<"\n";
	}
	in.close();
	out.close();
	return 0;
}