HeCao2008 @ 2022-07-14 20:14:36
#include<bits/stdc++.h>
using namespace std;
priority_queue<int , vector<int> , less <int > > _q;
priority_queue<int , vector<int> , greater <int> > __q;
int n,rubbish;
int main(){
cin>>n>>rubbish;
_q.push(rubbish);
cout<<_q.top()<<endl;
for(int i=2;i<=n;i++){
int x;cin>>x;
if(x>_q.top())__q.push(x);
else _q.push(x);
while(abs( int(_q.size()) - int(__q.size()) ) >1){
if(_q.size()>__q.size()){
__q.push(_q.top());
_q.pop();
}
else{
_q.push(__q.top());
__q.pop();
}
if(i%2==1){
if(_q.size()>__q.size())cout<<_q.top();
else cout<<__q.top();
}
}
}
return 0;
}
by liqingyang @ 2022-07-14 20:25:48
因为size返回的是unsigned类型,没有负数
by HeCao2008 @ 2022-07-14 20:44:39
@liqingyang 那应该怎么调呢
by liqingyang @ 2022-07-14 21:51:28
@HeCao2008 所以将他转化为int类型就有负数了啊
by HeCao2008 @ 2022-07-14 22:18:45
@liqingyang 哦,怪不得,怪不得呢
最后我用vector自带的二分过掉了