Wtbjp @ 2022-05-22 19:33:56
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL N=1e6+10;
LL n,m;
struct sb
{
LL lazy,l,r,lazy1;
LL maxx;
bool g;
}a[N*4];
void js(LL l,LL r,LL x)
{
a[x].l=l,a[x].r=r,a[x].g=0;
if(l==r)
{
cin>>a[x].maxx;
return;
}
LL mid=(l+r)/2;
if(l<=mid)js(l,mid,x*2);
if(r>mid)js(mid+1,r,x*2+1);
a[x].maxx=max(a[x*2+1].maxx,a[x*2].maxx);
}
void downop(int x)
{
if(a[x].g)
{
a[x*2].maxx=a[x].maxx;
a[x*2+1].maxx=a[x].maxx;
a[x*2].lazy=a[x].lazy;
a[x*2+1].lazy=a[x].lazy;
a[x*2].lazy1=0;
a[x*2+1].lazy1=0;
a[x*2].g=1;
a[x*2+1].g=1;
}
a[x*2].lazy1+=a[x].lazy1;
a[x*2+1].lazy1+=a[x].lazy1;
a[x].maxx+=a[x].lazy1;
a[x].lazy=0;
a[x].lazy1=0;
a[x].g=0;
}
void gai(LL l,LL r,LL s,LL x)
{
if(l<=a[x].l&&r>=a[x].r)
{
a[x].lazy1=0;
a[x].lazy=s;
a[x].maxx=s;
a[x].g=1;
return;
}
downop(x);
LL mid=(a[x].l+a[x].r)/2;
if(l<=mid)gai(l,r,s,x*2);
if(r>mid)gai(l,r,s,x*2+1);
a[x].maxx=max(a[x*2].maxx,a[x*2+1].maxx);
}
void jia(LL l,LL r,LL s,LL x)
{
if(l<=a[x].l&&r>=a[x].r)
{
a[x].lazy1+=s;
a[x].maxx+=s;
return;
}
downop(x);
LL mid=(a[x].l+a[x].r)/2;
if(l<=mid)jia(l,r,s,x*2);
if(r>mid)jia(l,r,s,x*2+1);
a[x].maxx=(a[x*2].maxx,a[x*2+1].maxx);
}
LL da(LL l,LL r,LL x)
{
if(a[x].l>=l&&a[x].r<=r) return a[x].maxx;
downop(x);
LL mid=(a[x].l+a[x].r)/2;
LL st=-1ll;
if(l<=mid)st=max(st,da(l,r,x*2));
if(r>mid)st=max(st,da(l,r,x*2+1));
return st;
}
int main()
{
// freopen("P1253_2.in","r",stdin);
// freopen("P1253_2.txt","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
js(1,n,1);
for(LL i=1,d,l,r,x;i<=m;i++)
{
cin>>d;
if(d==1)
{
cin>>l>>r>>x;
gai(l,r,x,1);
}
else if(d==2)
{
cin>>l>>r>>x;
jia(l,r,x,1);
}
else
{
cin>>l>>r;
cout<<da(l,r,1)<<endl;
}
}
return 0;
}
by Wtbjp @ 2022-05-22 19:35:41
海亮OI中人
by lxth @ 2022-05-22 20:42:11
牛p