代码:
#include<bits/stdc++.h>
using namespace std;
#define qwq ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const int N = 1000010, INF = 2147483647;
int n, hp[N], frt = 0;
void value()
{
hp[0] = 0;
for (int i = 1; i <= n; ++ i)
{
hp[i] = INF;
}
}
void top_to_bottom(int x)
{
if (x == 1)
return;
if (hp[x] > hp[x / 2])
swap(hp[x], hp[x / 2]), top_to_bottom(x / 2);
}
void bottom_to_top(int x)
{
if (hp[x * 2] == INF)
return;
int res = hp[x * 2] < hp[x * 2 + 1]? x * 2 : x * 2 + 1;
if (hp[x] > hp[res])
swap(hp[x], hp[res]), bottom_to_top(x / 2);
}
int main()
{
scanf("%d", &n);
value();
for (int i = 1; i <= n; ++ i)
{
int op;
scanf("%d", &op);
if (op == 1)
{
int x;
cin >> x;
hp[++ frt] = x;
top_to_bottom(frt);
}
if (op == 2)
printf("%d\n", hp[1]);
if (op == 3)
{
hp[1] = hp[frt], hp[frt --] = INF;
bottom_to_top(1);
}
}
return 0;
}