Loading... ```cpp #include<bits/stdc++.h> using namespace std; const int N = 1e6+10; int hp[N], idx; int n; void down(int k){ int t = k; if(hp[k << 1] < hp[t] && (k << 1) <= idx) t = k << 1; if(hp[k << 1 | 1] < hp[t] && (k << 1 | 1) <= idx) t = k << 1 | 1; if(t != k){ swap(hp[k], hp[t]); down(t); } } void up(int k){ while(k >> 1 && hp[k >> 1] > hp[k]){ swap(hp[k >> 1], hp[k]); k >>= 1; } } int main(){ scanf("%d", &n); int x, y; while(n--){ scanf("%d", &x); if(x == 1){ scanf("%d", &y); hp[++idx] = y; up(idx); }else if(x == 2) printf("%d\n", hp[1]); else hp[1] = hp[idx], idx--, down(1); } return 0; } ``` Last modification:February 1, 2023 © Allow specification reprint Like 0 如果觉得我的文章对你有用,请随意赞赏
Comment here is closed