Cod sursa(job #1792039)

Utilizator Emil64Emil Centiu Emil64 Data 29 octombrie 2016 23:08:54
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.3 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};
vector <numar> v;


char buff[20000];int pos=0, semn;
FILE*f=freopen("heapuri.in","r",stdin);
FILE*g=freopen("heapuri.out","w",stdout);
inline void read(int &nr){
    semn = 1;
    while(buff[pos] < '0' || buff[pos] > '9'){if(buff[pos]== '-' )semn = -1; if(++pos == 20000) fread(buff, 1, 20000, stdin), pos = 0;}
    nr = 0;
    while('0' <= buff[pos] && buff[pos] <= '9') {nr = nr * 10 + buff[pos] - '0';if(++pos == 20000) fread(buff, 1, 20000, stdin), pos = 0;}
    nr*=semn;
}

int main()
{
    int i, j, n, cr, nr, lg=0;
    numar numar;
    read(n);
    for(i=1; i<=n; i++)
    {

        read(cr);
        if(cr==1)
        {

            read(nr);
            numar.nr = nr;
            numar.index = ++lg;
            v.push_back(numar);
            push_heap(v.begin(), v.end(), cmp);
        }
        if(cr==2)
        {
            read(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());
        }
    }

}