————————————————————————————————————————————————————
修改一次的单调队列,借助单调队列求出区间内删除达到的最大值,再借助连续增长的l,r求解,挺好的题
——————————————————————————————————————————————————
#include<bits/stdc++.h> using namespace std; long long a[2000005],n,p,d,sum[2000005],q[2000005],last=1,hd,tl,t[2000005],ans; int main() { cin>>n>>p>>d; for(int i=1;i<=n;i++){cin>>a[i];sum[i]=sum[i-1]+a[i];} for(int i=d;i<=n;i++)t[i]=sum[i]-sum[i-d]; ans=d;q[++tl]=d; for(int i=d+1;i<=n;i++) { while(hd<=tl&&t[q[tl]]<t[i])tl--; q[++tl]=i; while(hd<=tl&&q[hd]-d+1<last)hd++; while(hd<=tl&&sum[i]-sum[last-1]-t[q[hd]]>p) { last++; while(hd<=tl&&q[hd]-d+1<last)hd++; } ans=max(i-last+1,ans); } cout<<ans; }
P3594 [POI2015]WIL-Wilcze do?y
原文:https://www.cnblogs.com/SFWR-YOU/p/11402662.html