Pagini recente » Cod sursa (job #1963207) | Cod sursa (job #1629146) | Cod sursa (job #2485917) | Cod sursa (job #668570) | Cod sursa (job #2721476)
#include <fstream>
#include <queue>
#include <unordered_set>
using namespace std;
struct Elem {
int value;
int index;
bool operator>(const Elem& other) const {
return value > other.value;
}
};
template <typename T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
int main() {
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
MinHeap<Elem> heap;
unordered_set<int> invalid;
int next_index = 1;
int n;
fin >> n;
for (int i = 0; i < n; i += 1) {
int type;
fin >> type;
if (type == 1) {
int value;
fin >> value;
heap.push(Elem{value, next_index});
next_index += 1;
} else if (type == 2) {
int index;
fin >> index;
invalid.insert(index);
} else {
while (invalid.find(heap.top().index) != invalid.end()) {
heap.pop();
}
fout << heap.top().value << "\n";
}
}
return 0;
}