Hack能AC,但原数据爆两个

P1725 琪露诺

microchip @ 2024-03-24 19:43:31

WA on #11 #12

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

struct node{
    int no,val;
}N;

int n,l,r,a[200050],dp[400050],len,ans=-2147483647;
deque<node> q;

int main()
{
    cin>>n>>l>>r;
    for(int i=0;i<=n;i++)cin>>a[i];
    len=r-l+1;
    memset(dp,-0x7f,sizeof(dp));
    dp[0]=0;
    for(int i=0;i<=n;i++){
        while(!q.empty()&&i-q.back().no>=len)q.pop_back();
        while(!q.empty()&&q.front().val<=dp[i])q.pop_front();
        N.no=i;N.val=dp[i];
        q.push_front(N);
        dp[i+l]=q.back().val+a[i+l];
    }for(int i=n+1;i<=2*n;i++)ans=max(ans,dp[i]);
    cout<<ans<<endl;
    return 0;
}

by L_zaa_L @ 2024-03-24 19:46:35

@microchip 数组开大点


by microchip @ 2024-03-24 19:54:38

@zaa A了,但不太懂额,原数据是2e5为什么要开大呢


by L_zaa_L @ 2024-03-25 07:12:16

@microchip +a[i+l]这个会超


by microchip @ 2024-03-25 14:14:15

@zaa 懂了,感谢大佬


|