Cod sursa(job #2734834)

Utilizator StarkillerCalin Stafie Starkiller Data 1 aprilie 2021 14:41:46
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.94 kb
#include <bits/stdc++.h>

using namespace std;

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

priority_queue <pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> heap;
int n, op, x, index_push;
bool stare[200002];

int main()
{
    fin >> n;
    for (int t = 1 ; t <= n; ++t)
    {
        fin >> op;
        switch(op)
        {
        case 1:
            {
                fin >> x;
                ++index_push;
                heap.push({x, index_push});
                stare[index_push] = 1;
                break;
            }
        case 2:
            {
                fin >> x;
                stare[x] = 0;

                break;
            }
        case 3:
            {
                while(stare[heap.top().second] == 0)
                    heap.pop();
                gout << heap.top().first << '\n';
                break;
            }
        }
    }
    return 0;
}