Description
给出一个长度为N的非负整数序列A_i,对于所有1 < = k < = (N + 1) / 2, 输出前1,3,5,…个数的中位数。
Format
Input
第1行为一个正整数N,表示了序列长度。
N<=10^5
第2行包含N个整数A_i
(-10^9 < = A_i < = 10^9)
Output
如题所示。
Samples
输入数据 1
7
1 3 5 7 9 11 6
Copy
输出数据 1
1
3
5
6
#include<bits/stdc++.h>
using namespace std;
int n,lk;
priority_queue<int> q1;
priority_queue<int,vector<int>,greater<int>> q2;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>lk;
q1.push(lk);
if(q1.size()-q2.size()>1){
int ee=q1.top();
q1.pop();
q2.push(ee);
}
if(!q2.empty()&&q1.top()>q2.top()){
int ww=q1.top();
int qq=q2.top();
q1.pop();
q2.pop();
q1.push(qq);
q2.push(ww);
}
if(i%2==1){
cout<<q1.top()<<endl;
}
}
return 0;
}