hateful_bug @ 2024-05-19 17:19:31
#include<bits/stdc++.h>
#define l(p) t[p].l
#define r(p) t[p].r
#define m(p) t[p].m
#define pdj(p) t[p].pdj
#define pdg(p) t[p].pdg
#define N 10000005
#define inf 1054114514
using namespace std;
long long n,m,typ,x,y,k,a[N];
struct xds
{
long l;//左
long r;//右
long m;//最大值
long pdj;//判断加
long pdg;//判断改
}t[N*4];
void bui(long long x,long long y,long long p)
{
l(p)=x;r(p)=y;pdj(p)=0;pdg(p)=inf;
if(x==y)
{m(p)=a[x];return;}
long long mid=(x+y)>>1;
bui(x,mid,p*2);
bui(mid+1,y,p*2+1);
m(p)=max(m(p*2),m(p*2+1));
}
void bj(long long p)
{
if(pdg(p)!=inf)
{
pdg(p*2)=pdg(p);
pdg(p*2+1)=pdg(p);
m(p*2)=pdg(p);
m(p*2+1)=pdg(p);
pdg(p)=inf;
}
else if(pdj(p)!=0)
{
pdj(p*2)+=pdj(p);
pdj(p*2+1)+=pdj(p);
m(p*2)+=pdj(p);
m(p*2+1)+=pdj(p);
pdj(p)=0;
}
}
void xg(long long x,long long y,long long k,long long p)
{
if(l(p)>=x&&r(p)<=y)
{m(p)=k;pdj(p)=0;pdg(p)=k;return;}
bj(p);
long long mid=(l(p)+r(p))>>1;
if(x<=mid)
xg(x,y,k,p*2);
if(y>mid)
xg(x,y,k,p*2+1);
m(p)=max(m(p*2),m(p*2+1));
}
void zj(long long x,long long y,long long k,long long p)
{
if(l(p)>=x&&r(p)<=y)
{
m(p)+=k;
if(pdg(p)!=inf)
pdg(p)+=k;
else
pdj(p)+=k;
return;
}
bj(p);
long long mid=(l(p)+r(p))>>1;
if(x<=mid)
zj(x,y,k,p*2);
if(y>mid)
zj(x,y,k,p*2+1);
m(p)=max(m(p*2),m(p*2+1));
}
long long cx(long long x,long long y,long long p)
{
if(l(p)>=x&&r(p)<=y)
return m(p);
bj(p);
long long mid=(l(p)+r(p))>>1;
long long val=-9223370000000000000;
if(x<=mid)
val=max(val,cx(x,y,p*2));
if(y>mid)
val=max(val,cx(x,y,p*2+1));
return val;
}
int main()
{
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i]);
bui(1,n,1);
for(int i=1;i<=m;i++)
{
scanf("%lld%lld%lld",&typ,&x,&y);
switch(typ)
{
case 1:
scanf("%lld",&k);
xg(x,y,k,1);
break;
case 2:
scanf("%lld",&k);
zj(x,y,k,1);
break;
case 3:
printf("%lld\n",cx(x,y,1));
break;
}
}
return 0;
}
by ZhangXuKun @ 2024-05-19 17:21:43
看不懂思密达