Pagini recente » Cod sursa (job #417258) | Cod sursa (job #2964398) | Cod sursa (job #378350) | Cod sursa (job #1820447) | Cod sursa (job #2740101)
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
ifstream f ("heapuri.in");
ofstream g ("heapuri.out");
template<typename T>
class custom_priority_queue : public std::priority_queue<T, std::vector<T>>
{
public:
bool remove(const T& value) {
auto it = std::find(this->c.begin(), this->c.end(), value);
if (it != this->c.end()) {
this->c.erase(it);
std::make_heap(this->c.begin(), this->c.end(), this->comp);
return true;
}
else {
return false;
}
}
};
int main()
{
custom_priority_queue<int> pq;
int n;
f >> n;
vector<int> ordine;
for (int i = 1; i <= n; ++i)
{
int tip;
f >> tip;
switch(tip)
{
case 1:
{
int x;
f >> x;
pq.push(-x);
ordine.push_back(x);
break;
}
case 2:
{
int x;
f >> x;
pq.remove(-ordine[x-1]);
break;
}
case 3:
g << -pq.top() << '\n';
break;
}
}
return 0;
}