Cod sursa(job #2275347)

Utilizator anamaria41Raicu Ana anamaria41 Data 3 noiembrie 2018 08:42:15
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.78 kb
#include <cstdio>
#include <queue>

using namespace std;

priority_queue < pair<int,int>, vector<pair<int, int>>, greater<pair<int,int>> > h;
int n, cnt, x, used[200050], c;

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

    scanf ("%d", &n);

    for ( int i=1; i<=n; i++ )
    {
        scanf ("%d", &c);

        if (c==1)
        {
            scanf ("%d", &x);
            cnt++;
            h.push ({x, cnt});
        }
        else if (c==2)
        {
            scanf ("%d", &x);
            used[x]=1;
        }
        else if (c==3)
        {
            while (!h.empty() && used[h.top().second])
                h.pop();
            printf ("%d\n", h.top().first);
        }
    }

    return 0;
}