Cod sursa(job #2743956)

Utilizator MihaelaDanilaDanila Mihaela MihaelaDanila Data 23 aprilie 2021 18:49:33
Problema Heapuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <iostream>
#include <fstream>
#include <set>
#include <vector>

using namespace std;

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

int n,operatie,x;
set<int> h;
vector<int> pozitii;

void push(int x){
    h.insert(x);
    pozitii.push_back(x);
}

void pop(int x){
    int poz = pozitii[x];
    h.erase(poz);
}

int afis(){
    auto it = h.begin();
    return *it;
}

int main()
{
    f>>n;
    for(int i=0;i<n;i++){
        f>>operatie;
        if(operatie == 1){
            f>>x;
            push(x);
        }
        if(operatie==2){
            f>>x;
            pop(x);
        }
        if(operatie == 3) g<<afis()<<'\n';
    }
    return 0;
}