Cod sursa(job #3371529)

Utilizator Gergo123Schradi Gergo Gergo123 Data 30 octombrie 2026 17:58:47
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include <iostream>
#include <fstream>
#include <set>

using namespace std;

ifstream fin("heapuri.in");
ofstream fout("heapuri.out");

const int MAXN = 200005;
int val_of_id[MAXN];

int main() {
    int n;
    fin>>n;
    set<pair<int, int>> s;
    int insert_count = 0;
    for (int i = 0; i < n; ++i) {
        int type;
        fin >> type;
        if (type == 1) {
            int x;
            fin >> x;
            insert_count++;
            val_of_id[insert_count] = x;
            s.insert({x, insert_count});

        }
        else if (type == 2) {
            int x;
            fin >> x;
            s.erase({val_of_id[x], x});

        }
        else if (type == 3) {
            fout << s.begin()->first << "\n";
        }
    }

    return 0;
}