Cod sursa(job #1294015)

Utilizator alexandra_udristoiuUdristoiu Alexandra Maria alexandra_udristoiu Data 16 decembrie 2014 21:17:46
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include<fstream>
#define DIM  999999
#include<vector>
using namespace std;
int n, i, x, t;
vector<int> v[1000001];
vector<int>::iterator it;
vector<int>::iterator poz(int x, int p){
	vector<int>::iterator it;
	for(it = v[p].begin(); it < v[p].end(); it++){
		if(x == *it){
			return it;
		}
	}
	return it;
}
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int main(){
	fin>> n;
	for(i = 1; i <= n; i++){
		fin>> t >> x;
		it = poz(x, x % DIM);
		if(t == 1){
			if(it == v[x % DIM].end()){
				v[x%DIM].push_back(x);
			}
		}
		if(t == 2){
			if(it != v[x % DIM].end()){
				v[x%DIM].erase(it);
			}
		}
		if(t == 3){
			if(it != v[x % DIM].end()){
				fout<<"1\n";
			}
			else{
				fout<<"0\n";
			}
		}
	}
	return 0;
}