0分求调

P1168 中位数

```cpp #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #define int long long using namespace std; priority_queue<int,vector<int>,greater<int> > q1; priority_queue<int> q2; signed main() { int n,x; cin >> n >> x; q1.push(x); cout << x << endl; for (int i = 1;i <= n - 2;i += 2)//多输出一行 { cin >> x; if (x <= q1.top()) q2.push(x); else q1.push(x); cin >> x; if (x <= q1.top()) q2.push(x); else q1.push(x); while(q1.size() > q2.size() + 1) { q2.push(q1.top()); q1.pop(); } while(q1.size() < q2.size() + 1) { q1.push(q2.top()); q2.pop(); } cout << q1.top() << endl; } if(n % 2 == 0) cin >> x; return 0; } ```
by muyangli @ 2022-11-06 08:10:25


@[codejiahui](https://www.luogu.com.cn/user/512407)
by muyangli @ 2022-11-06 09:14:40


|