Cod sursa(job #2758250)

Utilizator andreiomd1Onut Andrei andreiomd1 Data 9 iunie 2021 11:42:46
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.93 kb
#include <iostream>
#include <cstdio>
#include <queue>

using namespace std;

const int NMAX = 2e5 + 1;

typedef pair < int, int > PII;

int Q;

int N = 0;
bool IsActive[NMAX];

auto cmp = [] (PII A, PII B)
{
    if(!(A.first < B.first))
        return 1;

    return 0;
};
priority_queue < PII, vector < PII >, decltype (cmp) > H (cmp);

namespace InParser
{
static const int BSIZE = (1 << 16);

static int pos = (BSIZE - 1);
static char buff[BSIZE];

static inline char Char ()
{
    ++pos;

    if(pos == BSIZE)
    {
        pos = 0;

        int n = fread(buff, 1, BSIZE, stdin);

        if(n != BSIZE)
            for(int i = n; i < BSIZE; ++i)
                buff[i] = 0;
    }

    return buff[pos];
}

inline int Int ()
{
    int ans = 0;

    for( ; ; )
    {
        char Ch = Char();

        if(Ch >= '0' && Ch <= '9')
        {
            ans = (int)(Ch - '0');

            break;
        }
    }

    for( ; ; )
    {
        char Ch = Char();

        if(Ch >= '0' && Ch <= '9')
            ans = ans * 10 + (int)(Ch - '0');
        else break;
    }

    return ans;
}
};

static inline void TestCase ()
{
    short int _type = InParser :: Int();

    if(_type <= 2)
    {
        int X = InParser :: Int();

        if(_type == 1)
            H.push({X, (++N)}), IsActive[N] = 1;
        else IsActive[X] = 0;
    }
    else
    {
        while(!H.empty() && !IsActive[H.top().second])
            H.pop();

        printf("%d\n", H.top().first);
    }

    return;
}

static inline void Fast_IO ()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);

    freopen("heapuri.in", "r", stdin);
    freopen("heapuri.out", "w", stdout);

    return;
}

static inline void Solve ()
{
    Fast_IO();

    Q = InParser :: Int();

    while(Q--)
        TestCase();

    return;
}

int main()
{
    Solve();

    return 0;
}