Cod sursa(job #613345)

Utilizator razyelxrazyelx razyelx Data 21 septembrie 2011 23:37:27
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.97 kb
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
const int P = 666013;	
vector <int> hash[P];


void add(int v){
	int idx = v % P;
	vector<int>::iterator it;
	
	it = find(hash[idx].begin(), hash[idx].end(), v);	
	if ( it == hash[idx].end()) 
		hash[idx].push_back(v);	
}
void rem(int v){
	int idx = v % P;
	vector<int>::iterator it;
	
	it = find(hash[idx].begin(), hash[idx].end(), v);	
	if ( it != hash[idx].end()) 
		hash[idx].erase(it);	
}

int contain(int v){	
	int idx = v % P;
	vector<int>::iterator it;
	
	it = find(hash[idx].begin(), hash[idx].end(), v);	
	if ( it != hash[idx].end()) 
		return 1;
	return 0;	
}


int main(){
	
	ifstream fin("hashuri.in");
	ofstream fout("hashuri.out");
	
	int n, op, v;	
	
	fin >> n;
	
	for (int i = 0; i < n; i++) {
		fin >> op >> v;
		
		if ( op == 1)
			add(v);
		if ( op == 2)
			rem(v);
		if ( op == 3)
			fout << contain(v) << '\n';
		
	}

	return 0;
}