排序2:动态中位数
作者:
总打瞌睡的天天啊
,
2024-08-05 15:38:30
,
所有人可见
,
阅读 2
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int N=100010;
int main()
{
int t;
cin>>t;
while(t--)
{
int k,n;
cin>>k>>n;
cout<<k<<' '<<(n+1)/2<<endl;
priority_queue<int> down;
priority_queue<int,vector<int>,greater<int>>up;
int cnt=0;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
if(down.empty()||x<=down.top())down.push(x);
else up.push(x);
if(down.size()>up.size())up.push(down.top()),down.pop();
if(up.size()>down.size())down.push(up.top()),up.pop();
if(i%2)
{
cout<<down.top()<<' ';
if(++cnt%10==0)puts("");
}
}
if(cnt%10!=0) puts(" ");
}
return 0;
}