Cod sursa(job #2740101)

Utilizator realmeabefirhuja petru realmeabefir Data 11 aprilie 2021 14:40:46
Problema Heapuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.2 kb
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>

using namespace std;

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

template<typename T>
class custom_priority_queue : public std::priority_queue<T, std::vector<T>>
{
  public:

      bool remove(const T& value) {
        auto it = std::find(this->c.begin(), this->c.end(), value);
        if (it != this->c.end()) {
            this->c.erase(it);
            std::make_heap(this->c.begin(), this->c.end(), this->comp);
            return true;
       }
       else {
        return false;
       }
 }
};

int main()
{
    custom_priority_queue<int> pq;
    int n;
    f >> n;
    vector<int> ordine;

    for (int i = 1; i <= n; ++i)
    {
        int tip;
        f >> tip;
        switch(tip)
        {
        case 1:
        {
            int x;
            f >> x;
            pq.push(-x);
            ordine.push_back(x);
            break;
        }
        case 2:
        {
            int x;
            f >> x;
            pq.remove(-ordine[x-1]);
            break;
        }
        case 3:
            g << -pq.top() << '\n';
            break;
        }
    }
    return 0;
}