qiutiao

P1725 琪露诺

Z_kazuha @ 2024-11-05 19:09:53

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
int n,l,r,a[N],f[N],tree[N<<2],kazuha;
int ls(int p){return p<<1;}
int rs(int p){return p<<1|1;}
void pushup(int p){
    tree[p]=max(tree[ls(p)],tree[rs(p)]);
}
void update(int p,int pl,int pr,int L,int d){
    if(pl==pr){
        tree[p]=d;
        return;
    }
    int mid=(pl+pr)>>1;
    if(L<=mid)update(ls(p),pl,mid,L,d);
    else update(rs(p),mid+1,pr,L,d); 
    pushup(p);
}
int query(int p,int pl,int pr,int L,int R){
    cout<<p<<" "<<pl<<" "<<pr<<endl;
    if(L<=pl&&pr<=R){
        return tree[p];
    }
    int mid=(pl+pr)>>1,res=-2147483647;
    if(L<=mid)res=query(ls(p),pl,mid,L,R);
    if(R>mid)res=max(res,query(rs(p),mid+1,pr,L,R));
    return res;
}
signed main(){
    cin>>n>>l>>r;
    n++;
    for(int i=1;i<=n;i++)cin>>a[i];
    f[1]=a[1];
    update(1,1,n,1,a[1]);
    for(int i=l;i<=n;i++){
        f[i]=query(1,1,n,max(1ll,i-r),min(n,i-l))+a[i];
        update(1,1,n,i,f[i]);
        if(i>=n-r+1&&i<=n)kazuha=max(kazuha,f[i]);
    }
    cout<<kazuha;
    return 0;
}

query RE


|