Cod sursa(job #3123881)

Utilizator MihaiZ777MihaiZ MihaiZ777 Data 25 aprilie 2023 19:52:33
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#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';
        }
    }
}