题目大意:有一串数,有一个长度为k的木板,求木板每次移动后覆盖的最大值

题解:单调队列

 

C++ Code:

#include<cstdio>
using namespace std;
const int maxn=2000100;
int n,k;
int q[maxn],s[maxn],h,t;
int main(){
	scanf("%d%d",&n,&k);
	scanf("%d",&s[1]);
	q[h=t=1]=1;
	for (int i=2;i<=n;i++){
		scanf("%d",&s[i]);
		if (q[h]<i-k+1)h++;
		while (h<=t&&s[i]>s[q[t]])t--;
		q[++t]=i;
		if (i>=k)printf("%d\n",s[q[h]]);
	}
	return 0;
}

  

相关文章:

  • 2021-12-14
  • 2021-07-14
  • 2021-11-23
  • 2021-07-02
  • 2021-12-23
  • 2022-01-19
  • 2022-01-02
  • 2022-01-20
猜你喜欢
  • 2022-12-23
  • 2021-12-01
  • 2021-09-08
  • 2021-08-10
  • 2021-08-05
  • 2021-05-18
  • 2021-06-30
相关资源
相似解决方案