Cod sursa(job #3163611)

Utilizator andreea_condreaCondrea Andreea andreea_condrea Data 31 octombrie 2023 18:04:58
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.76 kb
#include <bits/stdc++.h>

using namespace std;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > pq, pq2;
vector<int> v;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
int main()
{
    int n, poz, x, cod;
    fin>>n;
    v.resize(n);
    poz=1;
    while(n--){
        fin>>cod;
        if(cod==1){
            fin>>x;
            v[poz]=x;
            pq.push({x, poz});
            poz++;
        }else if(cod==2){
            fin>>x;
            pq2.push({v[x], x});
        }else{
            while(!pq.empty() && !pq2.empty() && pq.top().first==pq2.top().first){
                pq.pop();
                pq2.pop();
            }
            fout<<pq.top().first<<'\n';
        }
    }
    return 0;
}