题解
  • 板块灌水区
  • 楼主JefferyDeng
  • 当前回复7
  • 已保存回复7
  • 发布时间2021/7/15 17:52
  • 上次更新2023/11/4 14:43:18
查看原帖
题解
367321
JefferyDeng楼主2021/7/15 17:52

/dwd

#include<iostream> 
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
priority_queue<int,vector<int>,greater<int> >q;
priority_queue<int,vector<int>,less<int> >Q; 
int n;
int a[100005];
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
  	cin>>a[i];
  }
  if(a[1]>a[2]){
  	Q.push(a[2]);
  	q.push(a[1]);
  }
  else{
  	Q.push(a[1]);
  	q.push(a[2]);
  }
  printf("%d\n",a[1]);
  if(n>=3){
  	Q.push(a[3]);
  	while(Q.top()>q.top()){
  		int tmp=Q.top();
  		Q.pop();
  		int tmp2=q.top();
  		q.pop();
  		Q.push(tmp2);
  		q.push(tmp);
  	}
  }
  printf("%d\n",Q.top());
  for(int i=4;i<=n;i+=2){
  	if(i==n){
  		return 0;
  	}
  	if(a[i]>a[i+1]){
  		Q.push(a[i+1]);
  		q.push(a[i]);
  	}
  	else{
  		Q.push(a[i]);
  		q.push(a[i+1]);
  	}
  	while(Q.top()>q.top()){
  		int tmp=Q.top();
  		Q.pop();
  		int tmp2=q.top();
  		q.pop();
  		Q.push(tmp2);
  		q.push(tmp);
  	}
  	printf("%d\n",Q.top());
  }
  return 0;
}
2021/7/15 17:52
加载中...