Cod sursa(job #3163587)

Utilizator TeodoraMaria123Serban Teodora Maria TeodoraMaria123 Data 31 octombrie 2023 17:40:39
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.02 kb
#include <bits/stdc++.h>

using namespace std;

int n;
vector <int> poz;
priority_queue <int, vector <int>, greater <int>> allValues, deleteValues;

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    freopen("heapuri.in", "r", stdin);
    freopen("heapuri.out", "w", stdout);

    cin >> n;
    poz.push_back(0);
    for(int i = 1; i <= n; i ++)
    {
        int x;
        cin >> x;
        if(x == 1)
        {
            int val;
            cin >> val;
            allValues.push(val);
            poz.push_back(val);
        }
        else if(x == 2)
        {
            int val;
            cin >> val;
            deleteValues.push(poz[val]);
//            cout << poz[val] << "a ";
        }
        else
        {
           while(!deleteValues.empty()  &&  deleteValues.top() == allValues.top())
           {
               deleteValues.pop();
               allValues.pop();
           }
           cout << allValues.top() << "\n";
        }
    }
    return 0;
}