题目大意:有一串数,有一个长度为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 ",s[q[h]]); } return 0; }