Cod sursa(job #2013805)

Utilizator workwork work work Data 22 august 2017 14:16:43
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <bits/stdc++.h>

using namespace std;

FILE *F=fopen("heapuri.in", "r"), *G=fopen("heapuri.out", "w");
int n, x, y, k;
priority_queue<pair<int, int> > pq;
bitset<200005> v;

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