Pagini recente » Cod sursa (job #948516) | Cod sursa (job #944927) | Monitorul de evaluare | Cod sursa (job #1848205) | Cod sursa (job #2746341)
#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;
}