Cod sursa(job #2741714)

Utilizator andre.anghelacheAndreea Anghelache andre.anghelache Data 18 aprilie 2021 10:46:22
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <iostream>
#include <fstream>
#include <set>
using namespace std;

int pozitii[200001];
set<int> myheap;

void insereaza(int x, int &k){
    myheap.insert(x);
    pozitii[k]=x;
    k++;
}

void sterge(int x){
    myheap.erase(pozitii[x]);
}

int main() {

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

    int n, k=1, x, y;

    in>>n;

    for(int i=0; i<n; i++)
    {
        in>>x;
        if(x==1)
        {
            in>>y;
            insereaza(y, k);
        }
        if(x==2)
        {
            in>>y;
            sterge(y);
        }

        if(x==3)
        {
            out<<*myheap.begin()<<"\n";
        }

    }

    in.close();
    out.close();
    return 0;
}