单调队列80WA求调
查看原帖
单调队列80WA求调
1013142
Chizuru_Ichinose楼主2023/10/19 19:31
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int kMax=2e6+5;
int n,k,a[kMax],t=1;
deque<int> q;	
signed main() {
	scanf("%lld%lld",&n,&k);
	for(int i=1; i<=n; i++) scanf("%lld",&a[i]);
	cout<<0<<endl;
	for(int i=1; i<n; i++) {
		while(!q.empty() && a[i]<=q.back()) q.pop_back();
		q.push_back(a[i]);
		if(i-t>=k && q.front()!=a[t]) t++;
		else if(i-t>=k && q.front()==a[t]) {
			t++;
			q.pop_front();
		}
		printf("%lld\n",q.front());
	}
	return 0;
}
2023/10/19 19:31
加载中...