60pts萌新求调

P1253 扶苏的问题

wenza03 @ 2022-09-05 14:36:30

7-9WA 10RE 萌新求调

#include<cstdio>
#include<cstdlib>
#include<iostream>
#define ll long long
using namespace std;
const int maxn=1000010;
int lson(int now){return now<<1;}
int rson(int now){return now<<1|1;}
struct node{
    ll val,lazyall,maxval,lazyadd;
    bool lazy;
}tree[maxn*4];
ll num[maxn];
void pushup(int now)
{
    tree[now].maxval=max(tree[lson(now)].maxval,tree[rson(now)].maxval);
}
void build(int now,int l,int r)
{
    tree[now].maxval=-9223372036854775807;
    if(l==r)
    {
        tree[now].maxval=num[l];
        tree[now].val=num[l];
        return;
    }
    int mid=(l+r)>>1;
    build(lson(now),l,mid);
    build(rson(now),mid+1,r);
    pushup(now);
}
void cover(int now,int l,int r)
{
    if(tree[now].lazy==1)
    {
    tree[lson(now)].maxval=tree[now].lazyall;
    tree[rson(now)].maxval=tree[now].lazyall;
    tree[lson(now)].lazyall=tree[now].lazyall;
    tree[rson(now)].lazyall=tree[now].lazyall;
    tree[now].lazyadd=0;
    tree[lson(now)].lazyadd=0;
    tree[rson(now)].lazyadd=0;
    }
}
void pushdown(int now,int l,int r)
{
    int mid=(l+r)>>1;
    cover(now,l,r);
    tree[lson(now)].maxval+=tree[now].lazyadd;
    tree[rson(now)].maxval+=tree[now].lazyadd;
    tree[lson(now)].lazyadd+=tree[now].lazyadd;
    tree[rson(now)].lazyadd+=tree[now].lazyadd;
    tree[now].lazyadd=0;
    tree[now].lazyall=0;
    tree[now].lazy=0;
}
void updatej(int now,int l,int r,int xgl,int xgr,ll k )
{
    if(xgr<l||r<xgl) return;
    if(xgl<=l&&r<=xgr)
    {
        cover(now,l,r);
        tree[now].maxval+=k;
        tree[now].lazyadd+=k;
        return;
    }
    int mid=(l+r)>>1;
    pushdown(now,l,r);
    updatej(lson(now),l,mid,xgl,xgr,k);
    updatej(rson(now),mid+1,r,xgl,xgr,k);
    pushup(now);
}
void updateb(int now,int l,int r,int xgl,int xgr,ll k )
{
    if(xgr<l||r<xgl) return;
    if(xgl<=l&&r<=xgr)
    {
        tree[now].lazyadd=0;
        tree[now].lazy=1;
        tree[now].maxval=k;
        tree[now].lazyall=k;
        return;
    }
    int mid=(l+r)>>1;
    pushdown(now,l,r);
    updateb(lson(now),l,mid,xgl,xgr,k);
    updateb(rson(now),mid+1,r,xgl,xgr,k);
    pushup(now);
}
ll query(int now,int l,int r,int xgl,int xgr)
{
    if(xgr<l||r<xgl) return -9223372036854775807;
    if(xgl<=l&&r<=xgr) return tree[now].maxval;
    int mid=(l+r)>>1;
    pushdown(now,l,r);
    return max(query(lson(now),l,mid,xgl,xgr),query(rson(now),mid+1,r,xgl,xgr));
}
int main(){
    int op;
    ll n,m,t1,t2,t3,t4;
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&num[i]);
    }
    build(1,1,n);
    while(m--)
    {
        scanf("%d",&op);
        if(op==1)
        {
                scanf("%lld%lld%lld",&t2,&t3,&t4);
            updateb(1,1,n,t2,t3,t4);
        }
        else if(op==2)
        {
            scanf("%lld%lld%lld",&t2,&t3,&t4);
            updatej(1,1,n,t2,t3,t4);
        }
        else{
            scanf("%lld%lld",&t2,&t3);
            printf("%lld\n",query(1,1,n,t2,t3));
        }
    }
    return 0;
} 

|