Cod sursa(job #410256)

Utilizator AndreiDDiaconeasa Andrei AndreiD Data 4 martie 2010 11:02:55
Problema Hashuri Scor 40
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 n,tip,val,T;
vector<int> G[Mod+20];

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)
{
	int k=x%Mod;
	
	if (!cauta(x))
		return ;
	
	vector<int> :: iterator it;

	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, &val);
		
		if (tip==1) baga(val);
		else
		if (tip==2) sterge(val);
		else
		printf("%d\n", cauta(val));
	}
	
	
	fclose(stdin);
	fclose(stdout);
	
	return 0;
	
}