本地 AC,提交 RE
查看原帖
本地 AC,提交 RE
681036
OldDriverTree楼主2024/1/16 22:38

rt,本地和 IDE 都能过 #8,但是提交 #8 怎么 RE 了?查出来是输入的后 mm 个数中出现了负数

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+1;
int n,m,a[N],tax[N];
priority_queue<int> p;
priority_queue<int,vector<int>,greater<int> > q;

int read() {
	int x=0; bool f=true; char c=0;
	while (!isdigit(c) ) f&=(c^'-'),c=getchar();
	while (isdigit(c) ) x=(x<<3)+(x<<1)+(c&15),c=getchar();
	return f?x:-x;
}
int main()
{
	n=read(),m=read(),q.push(INT_MIN);
	for (int i=1;i<=n;i++) a[i]=read();
	while (m--) tax[read()]++;
	for (int i=1;i<=n;i++)
	{
		if (q.empty()||a[i]>=q.top() ) q.push(a[i]);
		else p.push(a[i]),q.push(p.top() ),p.pop();
		while (tax[i]--) {
			p.push(q.top() ),q.pop();
			printf("%d\n",q.top() );
		}
	}
	return 0;
}
2024/1/16 22:38
加载中...