Pagini recente » Cod sursa (job #2552941) | Cod sursa (job #2240577) | Cod sursa (job #956612) | Cod sursa (job #2999029) | Cod sursa (job #3124190)
#include <iostream>
#include <algorithm>
#include <queue>
class mheap : public std::priority_queue<int, std::vector<int>, std::greater<int>>
{
public:
bool _delete(const int& value) {
auto it = std::find(this->c.begin(), this->c.end(), value);
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;
int poz[200005];
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);
poz[j++] = x;
break;
}
case 2: {
std::cin >> x;
heap._delete(poz[x]);
break;
}
case 3: std::cout << heap.top() << '\n';
}
}
fclose(stdin);
fclose(stdout);
return 0;
}