大佬求调
查看原帖
大佬求调
1251882
123456adgj楼主2025/1/21 16:01
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,q,a[1000001],op,b,c,k;
struct node{
	int tag,lazy,l,r,w;
}t[5000001];
ll lt(ll x){return x<<1;}
ll rt(ll x){return x<<1|1;}
void up(ll x){t[x].w=max(t[lt(x)].w,t[rt(x)].w);}
void build(ll la,ll ra,ll x){
	t[x].l=la,t[x].r=ra,t[x].w=-100000000;
	if(la==ra){
		t[x].w=a[la];
		return;
	}
	ll mid=la+ra>>1;
	build(la,mid,lt(x));
	build(mid+1,ra,rt(x));
	up(x);
}
void f(ll x,ll k,ll h){
	if(h){
		t[x].lazy=h;
		t[x].w=h;
		t[x].tag=0;
	}
	else{
		if(t[x].lazy)t[x].lazy+=k;
		else t[x].tag+=k;
		t[x].w+=k;
	}
}
void down(ll x){
	f(lt(x),t[x].tag,t[x].lazy);
	f(rt(x),t[x].tag,t[x].lazy);
	t[x].lazy=t[x].tag=0;
}
void fx(ll la,ll ra,ll x,ll k,ll h){
	if(t[x].l>=la&&t[x].r<=ra){
		if(h==0){
		t[x].w+=k;
		if(t[x].lazy)t[x].lazy+=k;
		else t[x].tag+=k;
		}
		else{
			t[x].tag=0;
			t[x].lazy=h;
			t[x].w=h;
			}
			return;
	}
	down(x);
	ll mid=t[x].l+t[x].r>>1;
	if(mid>=la)fx(la,ra,lt(x),k,h);
	if(mid<ra)fx(la,ra,rt(x),k,h);
	up(x);
}
ll query(ll x,ll la,ll ra){
		if(t[x].l>=la&&t[x].r<=ra)return t[x].w;
		down(x);
		ll mid=t[x].l+t[x].r>>1;
		ll res=0;
		if(mid>=la)res=max(res,query(lt(x),la,ra));
		if(mid<ra)res=max(res,query(rt(x),la,ra));
		return res;
}
int main(){
	cin>>n>>q;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	build(1,n,1);
	for(int i=1;i<=q;i++){
		scanf("%d%d%d",&op,&b,&c);
		if(op==1){
			scanf("%d",&k);
			fx(b,c,1,0,k);
		}
		else if(op==2){
			scanf("%d",&k);
			fx(b,c,1,k,0);
		}
		else cout<<query(1,b,c)<<endl;
	}
	return 0;
}
2025/1/21 16:01
加载中...