单调队列WA*2,求debug qwq

P1725 琪露诺

无钩七不改名 @ 2022-12-10 12:25:20

RT.

提交记录:https://www.luogu.com.cn/record/96970264

代码:

#include<bits/stdc++.h>
using namespace std;

int n,l,r;
long long a[200005],dp[400005],ans,f[400005];

int main(){
    scanf("%d%d%d",&n,&l,&r);
    for(int i=0;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    int dl=1,dr=1;
    ans=-(1<<30);
    for(int i=0;i<=n+r;i++)dp[i]=-(1<<30);
    dp[0]=a[0];
    f[1]=0;
    for(int i=l;i<=n+r;i++){
        //dp[i]=-(1<<30);
        while(dl<=dr&&i-r>f[dl])dl++;
        while(dl<=dr&&dp[f[dr]]<=dp[i-l])dr--;
        f[++dr]=i-l;
        if(dl<=dr)dp[i]=dp[f[dl]]+a[i];
        //if(dp[i]!=-(1<<30))f[++dr]=i;
        //cout<<i<<" "<<f[dl]<<" "<<dp[i]<<endl;
    }
    for(int i=n+1;i<=n+r;i++)ans=max(ans,dp[i]);
    printf("%lld",ans);
    return 0;
}

by 无钩七不改名 @ 2023-11-17 23:13:21

@262620zzj 是这样的()


上一页 |