Cod sursa(job #1610958)

Utilizator tudormaximTudor Maxim tudormaxim Data 23 februarie 2016 20:51:54
Problema Heapuri Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

ifstream fin ("heapuri.in");
ofstream fout ("heapuri.out");

const int nmax = 200005;
vector <int> heap;
int ord[nmax], lg, v[nmax];

inline bool cmp (const int &x, const int &y)
{
    return x > y;
}

int main()
{
    ios_base::sync_with_stdio(false);
    vector <int> :: iterator it;
    int n, op, x, i;
    fin >> n;
    for(i=1; i<=n; i++)
    {
        fin >> op;
        if(op==1)
        {
            fin >> x;
            ord[++lg]=x;
            heap.push_back(x);
            push_heap(heap.begin(), heap.end(), cmp);
        }
        if(op==2)
        {
            fin >> x;
            it=find(heap.begin(), heap.end(), ord[x]);
            heap.erase(it);
            make_heap(heap.begin(), heap.end(), cmp);
        }
        if(op==3) fout << heap[0] << "\n";
    }
    fin.close();
    fout.close();
    return 0;
}