Cod sursa(job #389259)

Utilizator AndreiDDiaconeasa Andrei AndreiD Data 1 februarie 2010 13:02:12
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
#include <cstdio>
#include <vector>

using namespace std;

#define file_in "hashuri.in"
#define file_out "hashuri.out"

#define mod 666013

int T,x,tip;
vector<int> G[mod+10];

int cauta(int x)
{
	int k=x%mod;
	vector<int> :: iterator it;
	
	for (it=G[k].begin();it!=G[k].end();++it)
		 if (*it==x)
			 return 1;
		 
	return 0;
}


void baga(int x)
{
	int k=x%mod;
	if (cauta(x))
		return ;
	
	G[k].push_back(x);
}
	

void sterge(int x)
{
	if (!cauta(x))
		return ;
	
	
	vector<int> :: iterator it;
	
	int k=x%mod;
	
	for (it=G[k].begin();it!=G[k].end();++it)
		  if (*it==x)
		  {
			  G[k].erase(it);
			  return ;
		  }
}
	
	

int main()
{
	freopen(file_in,"r",stdin);
	freopen(file_out,"w",stdout);
	
	scanf("%d", &T);
	
	while(T--)
	{
		scanf("%d %d", &tip, &x);
		
		if (tip==1)
			baga(x);
		else
		if (tip==2)
			sterge(x);
		else
			printf("%d\n", cauta(x));
	}
	
	
	fclose(stdin);
	fclose(stdout);
	
	return 0;
	
}