Cod sursa(job #913652)

Utilizator EduardGeorgescuGeorgescu Eduard EduardGeorgescu Data 13 martie 2013 17:46:52
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.02 kb
#include<cstdio>
#include<vector>

using namespace std;

#define MOD 66013

int N;
vector <int> G[MOD];

inline vector<int>::iterator find_value(int x){
	
	int lista = x % MOD;
	
	vector<int>::iterator it;
	
	for(it=G[lista].begin() ; it != G[lista].end() ; it++)
		if(*it == x)
			return it;
		
	return G[lista].end();

}

inline void insert_value(int x){
	
	int lista = x % MOD;
	
	if(find_value(x) == G[lista].end() )
		G[lista].push_back(x);
	
}

inline void erase_value (int x){
	
	int lista = x % MOD;
	vector <int>::iterator it = find_value(x) ;
	
	if( it != G[lista].end() )
		G[lista].erase(it);
	
}
	

int main(){
	
	freopen("hashuri.in","r",stdin);
	freopen("hashuri.out","w",stdout);
	
	scanf("%d" , &N);
	
	int i;
	int op,x;
	
	for ( i = 1 ; i <= N ; i++){
		scanf("%d%d" , &op , &x);
		
		if(op == 1)	
			insert_value(x);
		
		else
			if(op == 2)
				erase_value(x);
			
			else
				printf("%d\n" , find_value(x) != G[x % MOD].end() );

	}

	return 0;
}