Cod sursa(job #732215)

Utilizator Stefana_fFratean Stefana Stefana_f Data 9 aprilie 2012 22:09:49
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.93 kb
#include <fstream>
#include <vector>
#define val 666013
using namespace std;

int n;
vector <int> mul[val];

inline vector<int>::iterator cautare(int x){
	vector <int>::iterator it;
	int pos = x % val;
	for(it = mul[pos].begin(); it != mul[pos].end(); ++it)
		if(*it == x)
			return it;
	return mul[pos].end();
}

inline void inserare(int x){
	int pos = x % val;
	if(cautare(x) == mul[pos].end())
		mul[pos].push_back(x);
}

inline void stergere(int x){
	int pos = x % val;
	vector<int>::iterator it = cautare(x);
	if (it != mul[pos].end())
		mul[pos].erase(it);
}

int main(){
	int operatie, x;
	ifstream f("hashuri.in");
	ofstream g("hashuri.out");
	f >> n;
	for(int i = n; i >= 1; --i){
		f >> operatie >> x;
		if(operatie == 1){
			inserare(x);
			continue;
		}
		if(operatie == 2){
			stergere(x);
			continue;
		}
		g << (cautare(x) != mul[x % val].end());
	}
	f.close();
	g.close();
	return 0;
}