60pts求调(玄关)

P1253 扶苏的问题

Hero_Broom @ 2024-08-21 20:18:42

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1000010,INF=0x7f7f7f7f7f7f7f;
struct node{
    int l,r,maxn,cover_tag,sum_tag;
};
int input[N],n,m,cmd,t1,t2,t3;
node tree[N<<2];
void biuld(int k,int l,int r){
    tree[k].l=l,tree[k].r=r;
    tree[k].cover_tag=-INF;
    tree[k].sum_tag=0;
    if(l==r){
        tree[k].maxn=input[l];
        return;
    }
    int mid=l+r>>1;
    if(l<=mid) biuld(k<<1,l,mid);
    if(mid+1<=r) biuld(k<<1|1,mid+1,r);
    tree[k].maxn=max(tree[k<<1].maxn,tree[k<<1|1].maxn);
}
void push_down_cover(int k){
    if(tree[k].cover_tag==-INF) return;
    tree[k<<1].sum_tag=tree[k<<1|1].sum_tag=0;
    tree[k<<1].cover_tag=tree[k<<1|1].cover_tag=tree[k].cover_tag;
    tree[k<<1].maxn=tree[k<<1].maxn=tree[k].cover_tag;
    tree[k].cover_tag=-INF;
}
void push_down_sum(int k){
    if(tree[k].sum_tag==0) return;
    push_down_cover(k);
    tree[k<<1].sum_tag+=tree[k].sum_tag;
    tree[k<<1|1].sum_tag+=tree[k].sum_tag;
    tree[k<<1].maxn+=tree[k].sum_tag;
    tree[k<<1|1].maxn+=tree[k].sum_tag;
    tree[k].sum_tag=0;
}
inline void push_down(int k){
    push_down_cover(k);
    push_down_sum(k);
}
void update_cover(int k,int l,int r,int z){
    if(tree[k].l>=l&&tree[k].r<=r){
        tree[k].maxn=z;
        tree[k].sum_tag=0;
        tree[k].cover_tag=z;
        return;
    }
    push_down(k);
    if(tree[k<<1].r>=l) update_cover(k<<1,l,r,z);
    if(tree[k<<1|1].l<=r) update_cover(k<<1|1,l,r,z);
    tree[k].maxn=max(tree[k<<1].maxn,tree[k<<1|1].maxn);
}
void update_add(int k,int l,int r,int z){
    if(tree[k].l>=l&&tree[k].r<=r){
        push_down_cover(k);
        tree[k].maxn+=z;
        tree[k].sum_tag+=z;
        return;
    }
    push_down(k);
    if(tree[k<<1].r>=l) update_add(k<<1,l,r,z);
    if(tree[k<<1|1].l<=r) update_add(k<<1|1,l,r,z);
    tree[k].maxn=max(tree[k<<1].maxn,tree[k<<1|1].maxn);
}
int query_max(int k,int l,int r){
    if(tree[k].l>=l&&tree[k].r<=r) return tree[k].maxn;
    push_down(k);
    int ans=-INF;
    if(tree[k<<1].r>=l) ans=max(ans,query_max(k<<1,l,r));
    if(tree[k<<1|1].l<=r) ans=max(ans,query_max(k<<1|1,l,r));
    return ans;
}
signed main(){
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++) scanf("%lld",&input[i]);
    biuld(1,1,n);
    while(m--){
        scanf("%lld%lld%lld",&cmd,&t1,&t2);
        switch(cmd){
            case 1:
                scanf("%lld",&t3);
                update_cover(1,t1,t2,t3);
                break;
            case 2:
                scanf("%lld",&t3);
                update_add(1,t1,t2,t3);
                break;
            case 3:
                printf("%lld\n",query_max(1,t1,t2));
                break;
        }
    }
}

by lyas145 @ 2024-08-22 13:08:24

27tree[k<<1].maxn=tree[k<<1].maxn=tree[k].cover_tag; 改成 tree[k<<1].maxn=tree[k<<1|1].maxn=tree[k].cover_tag; 就行了 @Hero_Broom


by Hero_Broom @ 2024-08-22 14:17:09

@lyas145 thx,已关,但交上去只有90pts,能在帮忙看看吗?


by Hero_Broom @ 2024-08-22 14:20:58

@lyas145 没事,已经过了,数组开小了


|