Cod sursa(job #3215350)

Utilizator andreipirjol5Andrei Pirjol andreipirjol5 Data 14 martie 2024 20:41:48
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include <iostream>
#include <fstream>
#include <queue>

using namespace std;

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

const int NMAX = 2 * (1e5);
int v[NMAX + 5], Size, n;
bool fr[NMAX + 5];

struct cmp
{
    bool operator()(int ind1, int ind2)
    {
        return v[ind1] > v[ind2];
    }
};

priority_queue <int, vector<int>, cmp> heap;

int main()
{
    fin >> n;
    for(int i = 1; i <= n; i++)
    {
        int op, value;
        fin >> op;
        if(op == 1)
        {
            fin >> value;
            v[++Size] = value;
            fr[Size] = 1;
            heap.push(Size);
        }
        if(op == 2)
        {
            fin >> value;
            fr[value] = 0;
        }
        if(op == 3)
        {
            while(fr[heap.top()] == 0)
                heap.pop();
            fout << v[heap.top()] << '\n';
        }
    }
    return 0;
}