萌新线段树20tps求调

P1253 扶苏的问题

FIRESTARS @ 2024-08-19 20:46:57

#include<bits/stdc++.h>
using namespace std;
int a[1000005],t[4000005],b[40000005],b2[40000005];
void build(int v,int tl,int tr)
{
    if(tl==tr)
    {
        t[v]=a[tl];
        return;
    }
    int tm=(tl+tr)/2;
    build(v*2,tl,tm);
    build(v*2+1,tm+1,tr);
    t[v]=max(t[v*2],t[v*2+1]);
}
int getmax(int v,int tl,int tr,int l,int r)
{
    if(tl>=l&&tr<=r)return t[v];
    int tm=(tl+tr)/2;
    int s1=0,s2=0;
    if(tm>=l)s1=getmax(v*2,tl,tm,l,r);
    if(tm<r)s2=getmax(v*2+1,tm+1,tr,l,r);
    return max(s1,s2);
}
void updata(int v,int tl,int tr,int l,int r,int x)
{
    if(l<=tl&&tr<=r)
    {
        t[v]=x;b[v]=1;
        return;
    }
    if(b[v]!=0)
    {
        t[v*2]=t[v];
        t[v*2+1]=t[v];
        b[v*2]=t[v];
        b[v*2+1]=t[v];
        b[v]=0;
    }
    int tm=(tl+tr)/2;
    if(tm>=l)updata(v*2,tl,tm,l,r,x);
    if(tm<r)updata(v*2+1,tm+1,tr,l,r,x);
    t[v]=max(t[v*2],t[v*2+1]);
    return;
}
void updata2(int v,int tl,int tr,int l,int r,int x)
{
    if(l<=tl&&tr<=r)
    {
        t[v]+=x;b2[v]+=x;
        return;
    }
    int tm=(tl+tr)/2;
    if(b2[v]!=0)
    {
        t[v*2]+=b2[v]*(tm-tl+1);
        t[v*2+1]+=b2[v]*(tr-tm);
        b2[v*2]+=b2[v];
        b2[v*2+1]+=b2[v];
        b2[v]=0;
    }
    if(tm>=l)updata2(v*2,tl,tm,l,r,x);
    if(tm<r)updata2(v*2+1,tm+1,tr,l,r,x);
    t[v]=max(t[v*2],t[v*2+1]);
    return;
}
signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n,q;cin>>n>>q;
    for(int i=1;i<=n;i++)cin>>a[i];
    build(1,1,n);
    while(q--)
    {
        int opt,l,r,x;
        cin>>opt;
        if(opt==1)
        {
            cin>>l>>r>>x;
            updata(1,1,n,l,r,x);
        }
        else if(opt==2)
        {
            cin>>l>>r>>x;
            a[l]=r;
            updata2(1,1,n,l,r,x);
        }
        else if(opt==3)
        {
            cin>>l>>r;
            cout<<getmax(1,1,n,l,r)<<'\n';
        }
    }
}

by FIRESTARS @ 2024-08-19 20:51:23

@zhizhenyaohanyu IX


by Dejected @ 2024-08-19 20:51:49

@FIRESTARS 我们这样不会被禁言吧...


by zhizhenyaohanyu @ 2024-08-19 20:51:51

@FIRESTARS ,@zhizhenhuyuzhehyz他有病


by zhizhenyaohanyu @ 2024-08-19 20:52:40

@FIRESTARS 4??


by woshiyida @ 2024-08-19 20:53:26

gengen队队长需要我们的帮助!!!!


by FIRESTARS @ 2024-08-19 20:53:50

@zhizhenyaohanyu ?

验证码f86k,要是把86改成uc就好了(


by FIRESTARS @ 2024-08-19 20:54:15

@woshiyida 我不是!


by Patience_is @ 2024-08-19 20:54:29

@fire_flies 到


by woshiyida @ 2024-08-19 20:54:53

@FIRESTARS 大佬,那个人骂你的话我都记下来了,存文档里了


by FIRESTARS @ 2024-08-19 20:55:20

@General0826 gengen队,我们需要你们!


上一页 | 下一页