堆STL爆零求助!!!
查看原帖
堆STL爆零求助!!!
764950
TuringPuth楼主2024/7/22 15:28

样例都没问题!!!但是全WA了!!!求助!!

#include <bits/stdc++.h>
using namespace std;
int n,a,ans,x,y;
priority_queue<int>q;//tiny
priority_queue<int,vector<int>,greater<int> >p;//large
int main(){
	scanf("%d%d",&n,&a);
	ans=a;
	printf("%d\n",ans);
	for(int i=1;i<=n/2;i++){
		scanf("%d%d",&x,&y);
		if(x>y) swap(x,y);
		if(x<ans&&y<ans){
			p.push(ans);
			q.push(x);
			q.push(y);
			ans=q.top();
			q.pop();
		}
		else if(x>ans&&y>ans){
			q.push(ans);
			p.push(x);
			p.push(y);
			ans=p.top();
			p.pop();
		}
		else{
			q.push(x);
			p.push(y);
		}
		printf("%d\n",ans);
	}
	return 0;
}

这个做题思路有问题吗? 就是分两个堆

2024/7/22 15:28
加载中...