行动欲望π @ 2023-03-18 14:03:27
#include<bits/stdc++.h>
using namespace std;
#define int long long
int opt,j,k,qq;
struct www{
int l,r,large;
};
const int xx=4e6+10;
www tree[xx];
int lazy[xx],cover[xx];
int a[xx];
int l(int x){
return x<<1;
}
int read(){
int x=0,f=1;
char ch=getchar();
while(ch < '0' || ch > '9'){
if(ch=='-') f = -1;
ch = getchar();
}
while(ch >='0' && ch <= '9'){
x = (x<<3) + (x<<1) + ch - '0';
ch = getchar();
}
return x*f;
}
//不分类型的快读
//快写
void write(int x){
if(x<0){//判断负数
x=-x;
putchar('-');
}
if(x>9) write(x/10);//位值拆数,递归
putchar(x%10+'0');//按位输出
}
int r(int x){
return l(x)+1;
}
void updata(int x){
tree[x].large=max(tree[l(x)].large,tree[r(x)].large);
}
void push(int x){
lazy[l(x)]+=lazy[x];
lazy[r(x)]+=lazy[x];
if(cover[x]!=-3e18){
tree[l(x)].large=tree[r(x)].large=cover[x];
cover[l(x)]=cover[r(x)]=cover[x];
lazy[l(x)]=lazy[r(x)]=lazy[x];
}
tree[l(x)].large+=lazy[x];
tree[r(x)].large+=lazy[x];
lazy[x]=0;
cover[x]=-3e18;
}
void build(int x,int left,int right){
tree[x].l=left;
tree[x].r=right; cover[x]=-3e18;
if(left==right){
tree[x].large=a[left];
return;
}
int mid=(left+right)/2;
build(l(x),left,mid);
build(r(x),mid+1,right);
updata(x);
}
void gai(int x ,int left,int right,int k){
if(tree[x].l==left&&tree[x].r==right){
tree[x].large=k;
lazy[x]=0;
cover[x]=k;
return;
}
if(lazy[x]!=0||cover[x]!=-3e18)push(x);
if(tree[l(x)].r>=right) gai(l(x),left,right,k);
else if(tree[r(x)].l<=left) gai(r(x),left,right,k);
else{
gai(l(x),left,tree[l(x)].r,k);
gai(r(x),tree[r(x)].l,right,k);
}
updata(x);
}
void gai1(int x,int left,int right ,int k){
if(tree[x].l==left&& tree[x].r==right){
tree[x].large+=k;
lazy[x]+=k;
return ;
}
if(lazy[x]!=0||cover[x]!=-3e18) push(x);
if(tree[l(x)].r>=right) gai1(l(x),left,right,k);
else if(tree[r(x)].l<=left) gai1(r(x),left,right,k);
else{
gai1(l(x),left,tree[l(x)].r,k);
gai1(r(x),tree[r(x)].l,right,k);
}
updata(x);
}
int ask(int x,int left,int right ){
if(tree[x].l==left&&tree[x].r==right){
return tree[x].large;
}
if(lazy[x]!=0||cover[x]!=-3e18) push(x);
if(tree[l(x)].r>=right)return ask(l(x),left,right);
if(tree[r(x)].l<=left) return ask(r(x),left,right);
return max(ask(l(x),left,tree[l(x)].r),ask(r(x),tree[r(x)].l,right));
}
signed main(){
int n,q;
n=read();
q=read();
for(int i=1;i<=n;i++){
a[i]=read();
}
build(1,1,n);
for(int i=1;i<=q;i++){
opt=read();
j=read();
k=read();
if(opt==1){
qq=read();
gai(1,j,k,qq);
}
else if(opt==2){
qq=read();
gai1(1,j,k,qq);
}
else {
printf("%lld\n",ask(1,j,k));
}
}
return 0;
}
by _Minecraft12345 @ 2023-03-18 16:39:49
sqlm
by markding @ 2023-05-10 17:07:55
@_Minecraft12345
?6
by _Minecraft12345 @ 2023-05-11 16:28:28
@markding 我是ta同学,他已经过了
by markding @ 2023-05-24 11:01:56
@_Minecraft12345 这。。。
反正不影响,放在这里就行了(小小声