Cod sursa(job #652123)

Utilizator d.andreiDiaconeasa Andrei d.andrei Data 23 decembrie 2011 00:26:16
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <cstdio>
#include <vector>

using namespace std;

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

#define mod 666013

int tip,x,T;
vector<int> H[mod];

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

void add(int x){
	
	int key=x%mod;
	
	H[key].push_back(x);
}

void sterge(int x){
	
	int key=x%mod;
	vector<int> :: iterator it;
	
	for (it=H[key].begin();it!=H[key].end();++it)
		 if (*it==x){
			  H[key].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){
			if (!find(x))
			add(x);
		}
		else
		if (tip==2){
			if (find(x))
				sterge(x);
		}
		else
			printf("%d\n", find(x));
	}
	
	return 0;
}