Cod sursa(job #340288)

Utilizator szabotamasSzabo Tamas szabotamas Data 14 august 2009 00:03:28
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include <iostream>
#include <fstream>
#include <vector>

#define MAX 666013 

using namespace std;

vector<long> v[MAX];
long n,op,x;

long is(long x){
	long mod=x%MAX;
	for (vector<long>::iterator i=v[mod].begin(); i!=v[mod].end(); i++){
		if(x==*i)
			return 1;
	}
	return 0;
}

void insertx(long x){
	if(0==is(x))
		v[x%MAX].push_back(x);
}

void erasex(long x){
	if(1==is(x)){
		long mod=x%MAX;
		for (vector<long>::iterator i=v[mod].begin(); i!=v[mod].end(); i++){
			if (x==*i){
				v[mod].erase(i);
				return;
			}
		}
	}
}

int main(){
	ifstream fin("hashuri.in");
	ofstream fout("hashuri.out");
	for(fin >> n; n; --n){
		fin >> op >> x;
		if(op==1){
			insertx(x);
		}
		if(op==2){
			erasex(x);
		}
		if(op==3){
			fout << is(x) << "\n";
		}
	}
	return 0;
}