ACCcode:
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,x,mid;
priority_queue<int,vector<int>,less<int> >q1;//大根堆
priority_queue<int,vector<int>,greater<int> >q2;//小根堆
void solve() {
cin>>n;
cin>>x;
mid=x;
cout<<mid<<"\n";
for(int i=2;i<=n;i++){
cin>>x;
if(x>mid) q2.push(x);
else q1.push(x);
if(i%2==1){//第奇数次加入
while(q1.size()!=q2.size()){
if(q1.size()>q2.size()){
q2.push(mid);
mid=q1.top();
q1.pop();
}
else{
q1.push(mid);
mid=q2.top();
q2.pop();
}
}
cout<<mid<<"\n";
}
}
}
signed main() {
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
solve();
return 0;
}
做法二: