Cod sursa(job #2624705)

Utilizator filiptudose2007Tudose Filip filiptudose2007 Data 5 iunie 2020 10:28:15
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.86 kb
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> p;
priority_queue <p,vector<p>,greater<p>> h;
vector <int> v(200005);
vector <bool> sel(200005);
int n;
int main()
{
    freopen("heapuri.in","r",stdin);
    freopen("heapuri.out","w",stdout);
    cin.sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    int cnt=0;
    for(int i=1; i<=n; ++i)
    {
        int t;
        cin>>t;
        if(t==1)
        {
            int x;
            cin>>x;
            ++cnt;
            v[cnt]=x;
            h.push({x,cnt});
        }
        else if(t==2)
        {
            int x;
            cin>>x;
            sel[x]=true;
        }
        else if(t==3)
        {
            while(sel[h.top().second])
            {
                h.pop();
            }
            cout<<h.top().first<<'\n';
        }
    }
}