Cod sursa(job #3199962)

Utilizator brianabucur11Briana Bucur brianabucur11 Data 3 februarie 2024 09:10:53
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.76 kb
#include <bits/stdc++.h>

using namespace std;

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

const int NMAX=200005;
priority_queue<int, vector<int>, greater<int> > pq1, pq2;
int n, nr, poz[NMAX];

void afis () {
    while (pq2.size() && pq1.top()==pq2.top()) {
        pq1.pop();
        pq2.pop();
    }
    fout << pq1.top() << '\n';
}

void add (int x) {
    pq1.push(x);
    nr++;
    poz[nr]=x;
}

int main() {
    fin >> n;
    for (int i=1; i<=n; i++) {
        int c;
        fin >> c;
        if (c==3)
            afis();
        else {
            int x;
            fin >> x;
            if (c==1)
                add(x);
            else
                pq2.push(poz[x]);
        }
    }
    return 0;
}