Cod sursa(job #2744935)

Utilizator MihaelaDanilaDanila Mihaela MihaelaDanila Data 25 aprilie 2021 16:01:03
Problema Heapuri Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.88 kb
#include <iostream>
#include <fstream>
#include <set>
#include <vector>

using namespace std;

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

vector<int> pozitii;
set<int> h;

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

auto index(int x){
    set<int>::iterator it;
    int cnt = 0;
    for(it = h.begin(); it!=h.end(); it++){
        if(*it == x) return it;
    }
}

void pop(int x){
    int poz = pozitii[x-1];
    auto gasit = index(poz);
    h.erase(gasit);
}

int peak(){
    return *h.begin();
}

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