求助,define编译报错

P4513 小白逛公园

王炸拆开打 @ 2020-10-07 21:29:49

RT


#include<iostream>
#include<cstdio>
#define LL long long
using namespace std;
LL a[400001],n,m,P=0x7f7f7f7f7f7f7f7f;
struct tree{
    int l,r,sum,m,lm,rm;
    #define l(x) t[x].l
    #define rm(x) t[x].rm
    #define lm(x) t[x].lm
    #define r(x) t[x].r
    #define m(x) t[x].m
    #define sum(x) t[x].sum
}t[400004];
void spread(int p){
    sum(p)=sum(p*2)+sum(p*2+1);
    lm(p)=max(sum(p*2)+lm(p*2+1),lm(p*2));
    rm(p)=max(sum(p*2+1)+rm(p*2),rm(p*2+1));
    m(p)=max(max(m(p*2),m(p*2+1)),rm(p*2)+lm(p*2+1));
}
void build(int l,int r,int p){
    l(p)=l;r(p)=r;
    if(l==r) {
        sum(p)=lm(p)=rm(p)=m(p)=a[l];
        return;
    }
    int mid=(l+r)>>1;
    build(l,mid,p*2);
    build(mid+1,r,p*2+1);
    spread(p);
}
void change(int p,int x,int c){
    if(l(p)==r(p)){
        sum(p)=lm(p)=rm(p)=m(p)=c;
        return;
    }
    int mid=(l(p)+r(p))>>1;
    if(mid>=x) change(p*2,x,c);
    else change(p*2+1,x,c);
    spread(p);
}
tree ask(int p,int l,int r){
    if(l(p)>=l&&r(p)<=r) return sum(p);
    spread(p);
    int mid=(l(p)+r(p))>>1;
    if(l>mid) return ask(p*2,l,r);
    else if(r<=mid) return ask(p*2+1,l,r);
    else{
        tree x=ask(p*2,l,r),y=ask(p*2+1,l,r),ans;
        sum(ans)=sum(x)+sum(y);
        lm(ans)=max(sum(x)+lm(y),lm(x));
        rm(ans)=max(sum(y)+rm(x),rm(y));
        m(ans)=max(max(m(x),m(y)),rm(x)+lm(y));
        return ans;
    }
}
int main(){
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    build(1,n,1);
    for(int e=1;e<=m;e++){
        int si,ti,gi;
        scanf("%d%d%d",&si,&ti,&gi);
        if(si==1){
            if(ti>gi) swap(ti,gi);
            tree ans=ask(1,ti,gi);
            printf("%lld\n",ans.maxx);
        }
        else change(1,ti,gi);
    }
    return 0;
}

by chichichichi @ 2020-10-07 22:24:19

@王炸拆开打


by 王炸拆开打 @ 2020-10-08 07:35:12

@chichichichi OK


上一页 |