Pagini recente » Cod sursa (job #730754) | Cod sursa (job #1454389) | Cod sursa (job #2099272) | Cod sursa (job #2189481) | Cod sursa (job #1736948)
#include <bits/stdc++.h>
using namespace std;
void pushHeap(vector<int> &heap, int x)
{
heap.push_back(x);
push_heap(heap.begin(), heap.end(), greater<int>());
}
int popHeap(vector<int> &heap)
{
int x = heap.front();
pop_heap(heap.begin(), heap.end(), greater<int>());
heap.pop_back();
return x;
}
int main()
{
ifstream in("heapuri.in");
ofstream out("heapuri.out");
int N;
in >> N;
vector<int> heap;
vector<int> elems;
unordered_map<int,int> UMap;
while (N--)
{
int t, x;
in >> t;
if (t == 1)
{
in >> x;
elems.push_back(x);
pushHeap(heap, x);
UMap[x]++;
}
else if (t == 2)
{
in >> x;
int e = elems[x - 1];
UMap[e]--;
}
else
{
while (true)
{
x = heap.front();
if (UMap[x] == 0)
popHeap(heap);
else
break;
}
out << x << "\n";
}
}
return 0;
}