Cod sursa(job #1791426)

Utilizator Emil64Emil Centiu Emil64 Data 29 octombrie 2016 12:56:19
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.01 kb
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

struct numar{
    int nr, index;
};

bool cmp(numar& a, numar& b)
{
    return (a.nr>b.nr);
}

bool sters[100000001]={0};
//int o[200001]= {0};
vector <numar> v;

int main()
{
    int i, j, n, cr, nr, lg=0;
    numar numar;
    freopen ("heapuri.in", "r", stdin);
    freopen ("heapuri.out", "w", stdout);
    scanf("%d ", &n);
    for(i=1; i<=n; i++)
    {

        scanf("%d", &cr);
        if(cr==1)
        {

            scanf("%d", &nr);
            //o[++lg]=nr;
            numar.nr = nr;
            numar.index = ++lg;
            v.push_back(numar);
            push_heap(v.begin(), v.end(), cmp);
        }
        if(cr==2)
        {
            scanf("%d", &nr);
            sters[nr] = true;
        }
        if(cr==3)
        {
            while(sters[v.front().index])
            {
                pop_heap(v.begin(),v.end(),cmp);
                v.pop_back();
            }
            printf("%d\n", v.front());
        }
    }

}