Cod sursa(job #573161)

Utilizator Cristy94Buleandra Cristian Cristy94 Data 5 aprilie 2011 23:02:32
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include<cstdio>
#include<vector>
#define M 700001

using namespace std;

int N;
vector <int> a[M];

int cauta(int x){
	
	int hash=x%M;
	
	for(size_t i=0;i<a[hash].size();++i)
		if(a[hash][i]==x)
			return i;
	return -1;	
}

void adauga(int x){
	
	if(cauta(x) == -1){
		int hash=x%M;
		a[hash].push_back(x);
	}	
}

void sterge(int x){
	
	int poz=cauta(x);
	
	if(poz!=-1){
		int hash=x%M;
		a[hash].erase(a[hash].begin()+poz);
	}
}
int main(){

	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	
	scanf("%d",&N);
	
	for(int i=1;i<=N;++i){
		
		int tip,x;
		
		scanf("%d%d",&tip,&x);
		
		switch(tip){
			 case 1: adauga(x);
				     break;
		     case 2: sterge(x);
				     break;
			 case 3: printf("%d\n",(cauta(x)!=-1));
		}
	}
	
return 0;
}