Cod sursa(job #2932268)

Utilizator k20ySabaceag Marius k20y Data 2 noiembrie 2022 13:34:28
Problema Heapuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.86 kb
#include <bits/stdc++.h>
using namespace std;

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

#define pii pair<int,int>

bool comp(pii a,pii b)
{
    return a.second < b.second;
}

priority_queue<pii,vector<pii>,greater<pii> > heap;

void del(int poz)
{
    stack<pii> st;

    while(heap.top().second != poz)
    {
        st.push(heap.top());
        heap.pop();
    }

    heap.pop();

    while(!st.empty())
    {
        heap.push(st.top());
        st.pop();
    }
}

int main()
{
    int n; in>>n;

    int nr=0;
    while(n--)
    {
        int tip,x; in>>tip;

        if(tip != 3) in>>x;

        switch(tip)
        {
        case 1: heap.push({x,++nr});
            break;
        case 2: del(x);
            break;
        case 3: out<<heap.top().first<<'\n';
            break;
        }
    }
}