Cod sursa(job #2737008)

Utilizator Ssebi1Dancau Sebastian Ssebi1 Data 4 aprilie 2021 12:18:07
Problema Heapuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <bits/stdc++.h>

using namespace std;

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


int main() {
    int order[1001];
    int n,j=1;
    priority_queue<int> heap;

    f>>n;
    for(int i=0;i<n;i++)
    {
        int op,value;
        f>>op;
        if(op==1)
        {
            f>>value;
            heap.push((-1)*value);
            order[j++] = value;
        }
        else if(op==2)
        {
            f>>value;
            value = order[value];
            int removed[heap.size()+1],k=0;
            while(!heap.empty() && heap.top()!=(-1)*value)
            {
                removed[k++] = heap.top();
                heap.pop();
            }
            heap.pop();
            for(int i=0;i<k;i++)
                heap.push(removed[i]);
        }
        else if(op==3)
        {
            g<<(-1)*heap.top()<<'\n';
        }
    }
    return 0;
}