单调队列50分WA求助
查看原帖
单调队列50分WA求助
846661
ARIS1_0楼主2023/12/6 13:32

WA on #1,3,4,5,10

#include<bits/stdc++.h>
#define ll long long
using namespace std;
mt19937 myrand(time(0));
inline ll read(){
	ll x=0,w=1;
	char ch=0;
	while(ch<'0'||ch>'9'){
		if(ch=='-')w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+(ch-'0');
		ch=getchar();
	}
	return x*w;
}
void write(ll x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	static int sta[35];
	int top=0;
	do{
		sta[top++]=x%10,x/=10;
	}while(x);
	while(top)putchar(sta[--top]+'0');
	putchar('\n');
}
deque<ll>q;
int n,m,a[2000005];
main(){
	n=read();m=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++){
		if(q.empty())write(0);
		else write(q.back());
		if(q.size()>=m)q.pop_back();
		while(a[i]<q.front()&&!q.empty())q.pop_front();
		q.push_front(a[i]);
	}
	return 0;
}
2023/12/6 13:32
加载中...