Pagini recente » Cod sursa (job #60211) | Cod sursa (job #2064100) | Cod sursa (job #1751726) | Cod sursa (job #1926595) | Cod sursa (job #3124184)
#include <iostream>
#include <algorithm>
#include <queue>
struct _p { int x, y; };
inline bool operator==(const _p& a, const _p& b) { return a.x == b.x && a.y == b.y; }
inline bool operator!=(const _p& a, const _p& b) { return !(a == b); }
inline bool operator<(const _p& a, const _p& b) { return a.x < b.x; }
inline bool operator>(const _p& a, const _p& b) { return a.x > b.x; }
class mheap : public std::priority_queue<_p, std::vector<_p>, std::greater<_p>>
{
public:
bool _delete(const int& value) {
auto it = this->c.begin();
for(; it != this->c.end(); ++it) if(it->y == value) break;
if (it == this->c.end()) {
return false;
}
if (it == this->c.begin()) {
this->pop();
}
else {
this->c.erase(it);
std::make_heap(this->c.begin(), this->c.end(), this->comp);
}
return true;
}
};
int n, c, x, j = 1;
mheap heap;
int main()
{
freopen("heapuri.in", "r", stdin);
freopen("heapuri.out", "w", stdout);
std::cin >> n;
for(int i = 1; i <= n; ++i) {
std::cin >> c;
switch(c) {
case 1: {
std::cin >> x;
heap.push({x, j++});
break;
}
case 2: {
std::cin >> x;
heap._delete(x);
break;
}
case 3: std::cout << heap.top().x << '\n';
}
}
fclose(stdin);
fclose(stdout);
return 0;
}