社区讨论

哪里出问题了?

P2032扫描参与者 4已保存回复 5

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
5 条
当前快照
1 份
快照标识符
@lo1rqrga
此快照首次捕获于
2023/10/23 01:54
2 年前
此快照最后确认于
2023/11/03 02:32
2 年前
查看原帖
下载了第一个数据点,输出一模一样。为什么 WA ?QwQ
CPP
#include<bits/stdc++.h>
using namespace std;
struct cxk{
	int zhi,wei;
bool operator < (const cxk&b) const
{
	return zhi < b.zhi;
}
};
int n,k;
priority_queue<cxk> q;
cxk op,ba;
int a[1000005];
int main(){
	cin>>n>>k;
	for(int i=1,x;i<=k;i++){
		cin>>x;
		a[i]=x;
		op.zhi=x;
		op.wei=i;
		q.push(op);
	}
	ba=q.top();
		cout<<ba.zhi<<endl;
	for(int i=1,l=1;i<=n-k;i++,l++){
		int y;
		ba=q.top();
		op.wei=k+i;
		cin>>y;
		op.zhi=y;
		q.push(op);
		if(ba.wei<i+1||ba.wei>i+k)  q.pop();
		ba=q.top();
		cout<<ba.zhi<<endl;
	}
	return 0;
}

回复

5 条回复,欢迎继续交流。

正在加载回复...