Cod sursa(job #2007062)

Utilizator infomaxInfomax infomax Data 1 august 2017 18:58:56
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <bits/stdc++.h>

#define f first
#define s second

using namespace std;

FILE *F=fopen("heapuri.in", "r"), *G=fopen("heapuri.out", "w");

int n, x, y, k, a[200003];
priority_queue<pair<int, int> > pq;
bitset<200003> w;

int main()
{
    fscanf(F, "%d ", &n);
    for(int i = 0; i < n; ++ i)
    {
        fscanf(F, "%d ", &x);
        if(x == 1)
        {
            fscanf(F, "%d ", &y);
            a[++ k] = y;
            pq.push({-y, k});
        }
        else if(x == 2)
            fscanf(F, "%d ", &y), w[y] = 1;
        else
        {
            while(!pq.empty() && w[pq.top().s])
                pq.pop();
            fprintf(G, "%d\n", pq.top().f*-1);
        }
    }
    return 0;
}