蒟蒻活不了样例,求调qwq

P1253 扶苏的问题

Dino_chx @ 2023-05-10 16:19:59

#include<bits/stdc++.h>
#define inf LONG_LONG_MIN
#define ll long long
using namespace std;
const int N=1e5+7;
struct ST
{
    int l,r;
    ll maxn,covertag,addtag;
}tree[N<<2];
int a[N],n,q;
void pushup(int x)
{
    tree[x].maxn=max(tree[x<<1].maxn,tree[x<<1|1].maxn);
    return;
}
void build(int x,int l,int r)
{
    tree[x]={l,r,inf};
    if(l==r)
    {
        tree[x]={l,r,a[l],inf,0};
        return;
    } 
    int mid=l+r>>1;
    build(x<<1,l,mid);
    build(x<<1|1,mid+1,r);
    pushup(x);
    return;
}
void pushdown(int x)
{
    ST &rt=tree[x],&ls=tree[x<<1],&rs=tree[x<<1|1];
    if(rt.covertag!=inf)
    {
        ls.covertag=ls.maxn=rt.covertag;
        rs.covertag=rs.maxn=rt.covertag;
        ls.addtag=rs.addtag=0;
        rt.covertag=inf;
    }
    if(rt.addtag)
    {
        ls.addtag+=rt.addtag;
        rs.addtag+=rt.addtag;
        ls.maxn+=rt.addtag;
        rs.maxn+=rt.addtag;
        rt.addtag=0; 
    }
    return;
}
void cover(int x,int l,int r,int k)
{
    if(l<=tree[x].l&&r>=tree[x].r)
    {
        tree[x].addtag=0;
        tree[x].maxn=tree[x].covertag=k;
        return;
    }
    pushdown(x);
    int mid=tree[x].l+tree[x].r>>1;
    if(l<=mid)
        cover(x<<1,l,r,k);
    if(r>mid)
        cover(x<<1|1,l,r,k);
    pushup(x);
    return;
}
void add(int x,int l,int r,int k)
{
    if(l<=tree[x].l&&r>=tree[x].r)
    {
        tree[x].addtag+=k;
        tree[x].maxn+=k;
        return;
    }
    pushdown(x);
    int mid=tree[x].l+tree[x].r>>1;
    if(l<=mid)
        add(x<<1,l,r,k);
    if(r>mid)
        add(x<<1|1,l,r,k);
    pushup(x);
    return; 
}
ll query(int x,int l,int r)
{
    if(l<=tree[x].l&&r>=tree[x].r)
        return tree[x].maxn;
    pushdown(x);
    ll ans=inf;
    int mid=tree[x].l+tree[x].r>>1;
    if(l<=mid)  
        ans=max(ans,query(x<<1,l,r));
    if(r>mid)
        ans=max(ans,query(x<<1|1,l,r));
    return ans; 
}
void print()
{
    for(int i=1;i<=n;i++)
    {
        printf("%lld ",query(1,i,i));
    } 
    putchar('\n');
    return;
}
int main()
{
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    build(1,1,n);
//  print();
    while(q--)
    {
        int op,l,r,x;
        scanf("%d%d%d",&op,&l,&r);
        if(op==1)
        {
            scanf("%d",&x);
            cover(1,l,r,x);
//          print(); 
        }
        if(op==2)
        {
            scanf("%d",&x);
            add(1,l,r,x);
//          print();
        }
        if(op==3)
            printf("%lld\n",query(1,l,r))/*,print()*/;
    }
    return 0;
} 

|