Cod sursa(job #3168367)

Utilizator PsyDuck1914Feraru Rares-Serban PsyDuck1914 Data 12 noiembrie 2023 11:58:49
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include <bits/stdc++.h>

using namespace std;

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

struct heap{
    int val, poz;
    bool operator < (const heap other) const{
        return val > other.val;
    }
};

const int NMAX = 2e5;

priority_queue<heap> q;
bool marked[NMAX+1];

void update(int val, int poz){
    heap x;
    x.val = val;
    x.poz = poz;
    q.push(x);
}

void sterge(int poz){
    marked[poz] = true;
}

void top(){
    while(!q.empty() and marked[q.top().poz])
        q.pop();
    if(!q.empty())
        g << q.top().val <<"\n";
}

int main()
{
    int t;
    f >> t;
    
    int cnt = 0;
    
    for(int i=1; i<=t; i++){
        int c;
        f >> c;
        if(c == 3)
            top();
        else{
            int val;
            f >> val;
            if(c == 1)
                cnt ++, update(val, cnt);
            if(c == 2)
                sterge(val);
        }
    }

    return 0;
}