Pagini recente » Cod sursa (job #3124073) | Cod sursa (job #72211) | Cod sursa (job #1000880) | Cod sursa (job #629102) | Cod sursa (job #3123881)
#include <fstream>
#include <queue>
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
struct HeapNode {
int value;
int id;
bool operator < (const HeapNode& other) const {
return value > other.value;
}
};
int n;
priority_queue <HeapNode> heap;
bool deletedIDs[200005];
int main() {
fin >> n;
int id = 1;
for (int i = 1; i <= n; i++) {
int op;
fin >> op;
if (op == 1) {
int x;
fin >> x;
heap.push({x, id++});
}
else if (op == 2) {
int x;
fin >> x;
deletedIDs[x] = true;
}
else if (op == 3) {
while (deletedIDs[heap.top().id]) {
heap.pop();
}
fout << heap.top().value << '\n';
}
}
}