Cod sursa(job #3163668)

Utilizator Nasa1004Ema Nicole Gheorghe Nasa1004 Data 31 octombrie 2023 20:44:07
Problema Heapuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include <fstream>
#include <priority_queue>
#include <vector>

using namespace std;

ifstream cin("heapuri.in");
ofstream cout("heapuri.out");

priority_queue < pair < int, int >, vector < pair < int, int > >, greater < pair < int, int > > > pq, pq2;
vector < int > v;
int main()
{
    int n, poz = 1, x, cod;
    cin >> n;
    v.resize(n);

    while(n--)
    {
        cin >> cod;
        if(cod == 1)
        {
            cin >> x;
            v[poz] = x;
            pq.push({x, poz});
            poz++;
        }
        else if(cod==2)
        {
            cin >> x;
            pq2.push({v[x], x});
        }
        else
        {
            while(!pq.empty() && !pq2.empty() && pq.top().first == pq2.top().first)
            {
                pq.pop();
                pq2.pop();
            }
            cout << pq.top().first << '\n';
        }
    }
    return 0;
}