版本比较
4.10总结
正文
增加 25 行删除 21 行
176 行未改动全部展开177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206176 行未改动全部展开$O(n^2 \log n)$。```cpp#include <bits/stdc++.h>using namespace std;const int N = 1e5 + 5;int a[N];priority_queue<int> q[N];int main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int n;cin >> n;for (int i = 1; i <= n; i++){cin >> a[i];q[i] = q[i - 1];q[i].push(a[i]);}for (int i = 1, j = 1; i <= n; i += 2, j++){int x = j - 1;while (x--)q[i].pop();cout << q[i].top() << "\n";}return 0;}```176 行未改动全部展开177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210176 行未改动全部展开$O(n^2 \log n)$。```cpp#include <bits/stdc++.h>using namespace std;int main(){int n;cin >> n;vector<int> a(n + 5);for (int i = 1; i <= n; i++)cin >> a[i];priority_queue<int> q1;priority_queue<int, vector<int>, greater<int>> q2;for (int i = 1; i <= n; i++){if (q1.empty() || a[i] <= q1.top())q1.push(a[i]);elseq2.push(a[i]);if (q1.size() > q2.size() + 1){q2.push(q1.top());q1.pop();} else if (q2.size() > q1.size()){q1.push(q2.top());q2.pop();}if (i % 2 != 0)cout << q1.top() << "\n";}return 0;}```