Cod sursa(job #2742507)

Utilizator Ssebi1Dancau Sebastian Ssebi1 Data 21 aprilie 2021 07:32:41
Problema Heapuri Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.98 kb
#include <bits/stdc++.h>

using namespace std;

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


int main() {
    int order[1000000];
    int n,j=1;
    vector<int> heap;
    make_heap(heap.begin(),heap.end());

    f>>n;
    for(int i=0;i<n;i++)
    {
        int op,value;
        f>>op;
        if(op==1)
        {
            f>>value;
            heap.push_back((-1)*value);
            push_heap(heap.begin(), heap.end());
            order[j++] = value;
        }
        else if(op==2)
        {
            f>>value;
            value = order[value];
            vector<int>::iterator it;
            for(auto it = heap.begin(); it != heap.end(); ++it)
            {
                if(*it == (-1)*value)
                {
                    heap.erase(it);
                    push_heap(heap.begin(),heap.end());
                    break;
                }
            }


        }
        else if(op==3)
        {
            g<<(-1)*heap.front()<<'\n';
        }
    }
    return 0;
}