Pagini recente » Cod sursa (job #2803) | Cod sursa (job #1258606) | Cod sursa (job #2714324) | Cod sursa (job #369987) | Cod sursa (job #3131029)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
std::ifstream input_file("heapuri.in");
std::ofstream output_file("heapuri.out");
std::vector<int> heap;
std::vector<int> history;
void insert_element(int value){
heap.push_back(-value);
std::push_heap(heap.begin(),heap.end());
history.push_back(-value);
}
void delete_xth_element(int index){
auto it=std::find(heap.begin(),heap.end(),history[index-1]);
if(it!=heap.end()){
std::pop_heap(it,heap.end());
heap.pop_back();
}
}
void print_min(){
output_file<<-heap.front()<<"\n";
}
int main(){
int n;
input_file>>n;
for(int i=0;i<n;++i){
int operation;
input_file>>operation;
if(operation==1){
int x;
input_file>>x;
insert_element(x);
}
else if(operation==2){
int index;
input_file>>index;
delete_xth_element(index);
}
else if(operation==3){
print_min();
}
}
input_file.close();
output_file.close();
return 0;
}