Pagini recente » Cod sursa (job #3272189) | Cod sursa (job #1855938) | Cod sursa (job #651069) | Cod sursa (job #242446) | Cod sursa (job #1111444)
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
int main() {
ifstream cin("heapuri.in");
ofstream cout("heapuri.out");
priority_queue< pair<int, int>, vector< pair<int, int> >, greater< pair<int, int> > > heap;
vector<bool> erased;
int q;
cin >> q;
for (int inserted = 0; q > 0; --q) {
int type;
cin >> type;
if (type == 1) {
int value;
cin >> value;
heap.push(make_pair(value, inserted++));
erased.push_back(false);
} else if (type == 2) {
int index;
cin >> index;
erased[--index] = true;
} else if (type == 3) {
while (!heap.empty() && erased[heap.top().second])
heap.pop();
if (!heap.empty())
cout << heap.top().first << "\n";
else
cout << "-1\n";
}
}
cin.close();
cout.close();
return 0;
}