Cod sursa(job #1155216)

Utilizator roxana.istratePoenaru Roxana roxana.istrate Data 26 martie 2014 19:12:59
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#include <fstream>
#include <vector>

#define MAX  666133

using namespace std;

vector<int> hashs[MAX];

vector<int>::iterator findh(int val){
	int pos = val % MAX;
	vector<int>::iterator it;
	for(it = hashs[pos].begin(); it < hashs[pos].end(); it++){
		if(*it == val){
			return it;
		}
	}
	return hashs[pos].end();
}

void inserth(int val){
	int pos = val % MAX;
	if(findh(val) == hashs[pos].end())
		hashs[pos].push_back(val); 
}

void deleteh(int val){
	int pos = val % MAX;
	vector<int>::iterator it;
	if((it = findh(val)) != hashs[pos].end()){
		hashs[pos].erase(it);
	}
}


int main(){
	
	ifstream fin("hashuri.in");
	ofstream fout("hashuri.out");

	int n, op, val;

	fin >> n;

	for(int i = 0 ; i < n ; i++){
		fin >> op >> val;
		if(op == 1){
			inserth(val);
		}else{
			if(op == 2){
				deleteh(val);
			}else{
				//cout << op << val <<" ";
				int ok = ((findh(val) == hashs[val % MAX].end())? 0 : 1); 
				fout << ok << "\n";
			}
		}
	}
	return 0;
}