Cod sursa(job #745342)

Utilizator dutzulBodnariuc Dan Alexandru dutzul Data 11 mai 2012 11:17:14
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include <fstream>
#define pb push_back
#define M 666013
#include <vector>
using namespace std;
int i,j,n,m,tip;
int x;
int D;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector<int> V[M+1];
vector <int> ::iterator it;
void Push(int k)
{
	D=k%M;
    V[D].pb(k);
}
void Del(int k)
{
	D=k%M;
	for(it=V[D].begin();it!=V[D].end()&&*it!=k;++it);
	if (it!=V[D].end())
	V[D].erase(it);
}
int caut(int k)
{
	D=k%M;
	for(it=V[D].begin();it!=V[D].end()&&*it!=k;++it);
	
 if (it!=V[D].end())
	 return 1;
 else return 0;
}
int main()
{
	f>>n;
	
	for(j=1;j<=n;++j)
	{
		f>>tip>>x;
		if (tip==1) Push(x);
		if(tip==2) Del(x);
		if (tip==3)g<<caut(x)<<'\n';
		
		/*for(i=1;i<=30;++i,g<<'\n')
			for(it=V[i].begin();it!=V[i].end();++it) 
				g<<*it<<" ";
	*/}
	
	f.close();
	g.close();
}