Cod sursa(job #238951)

Utilizator bogdan2412Bogdan-Cristian Tataroiu bogdan2412 Data 3 ianuarie 2009 18:40:58
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

#define MAXM 200005

priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > H;
vector<bool> erase(MAXM);

int main()
{
    freopen("heapuri.in", "rt", stdin);
    freopen("heapuri.out", "wt", stdout);

    int M;
    int inserted = 0;
    for (scanf("%d", &M); M; M--)
    {
        int type, val;
        scanf("%d", &type);
        if (type == 3)
        {
            for (; erase[H.top().second]; H.pop());
            printf("%d\n", H.top().first);
            continue;
        }

        scanf("%d", &val);
        if (type == 1)
        {
            ++inserted;
            H.push(make_pair(val, inserted));
        }
        else
            erase[val] = true;
    }
    return 0;
}