Nu aveti permisiuni pentru a descarca fisierul grader_test2.ok
Cod sursa(job #1736942)
| Utilizator | Data | 2 august 2016 22:24:44 | |
|---|---|---|---|
| Problema | Heapuri | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 1.03 kb |
#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
{
do
{
x = popHeap(heap);
UMap[x]--;
} while (UMap[x] > 0);
out << x << "\n";
}
}
return 0;
}
