Cod sursa(job #2746341)

Utilizator vladalex420@gmail.comLuta Vlad Alexandru [email protected] Data 27 aprilie 2021 18:37:22
Problema Heapuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.95 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>


int main()
{

	std::ifstream f("heapuri.in");
	int n;
	f >> n;

	std::ofstream out("heapuri.out");

	std::vector<int> heap; // min heap;
	heap.reserve(n);

	std::vector<int> elemente;
	elemente.reserve(n);

	for (int i = 0; i < n; i++)
	{
		int op;
		f >> op;
		if (op == 1)
		{
			int x;
			f >> x;
			heap.push_back(x);
			std::push_heap(heap.begin(), heap.end(), std::greater<int>());

			elemente.push_back(x);

		}else if(op == 2)
		{
			int x;
			f >> x;

			int el = elemente[x-1];

			for(int i=0;i<heap.size(); i++)
			{
				if(heap[i] == el)
				{
					heap.erase(heap.begin() + i);
					std::make_heap(heap.begin(), heap.end(), std::greater<int>());
					break;
				}
			}

		}else if(op == 3)
		{
			int el = heap[0];
			out << el << "\n";

		}
	}



	out.close();

	return 0;
}