Cod sursa(job #1503418)

Utilizator TeodorCotetCotet Teodor TeodorCotet Data 16 octombrie 2015 02:25:36
Problema Hashuri Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include <fstream>
#include <vector>

using namespace std;

const int NMAX = 1000001;
const int M = 700000;

int N;

vector<int> h[M];


void adauga(int x) {

	h[x % M].push_back(x);

}

void sterge(int x) {

	int value = x % M;

	for(unsigned i = 0 ; i < h[value].size(); ++i)
		if(h[value][i] == x) {
			swap(h[value][i], h[value][ h[value].size() - 1]);
			break;
		}

	h[value].pop_back();
}

int interogare(int x) {

	int value = x % M;

	for(unsigned i = 0 ; i < h[value].size() ; ++i)
		if(h[value][i] == x)
			return 1;
	return 0;
}


int main() {

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

	fin >> N;

	while(N--) {

		int type; int x;

		fin >> type >> x;

		switch(type) {

			case 1: adauga(x); break;
			case 2: sterge(x); break;
			case 3: fout << interogare(x) << '\n'; break;
		}
	}

	return 0;
}