60pts求调!
查看原帖
60pts求调!
912779
isme1楼主2024/4/6 16:05
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,a[2000010],tree[9000100],tag[9000010],lab[9000010],INF=-1e18;
int ls(int p){
	return p*2;
}
int rs(int p){
	return p*2+1;
}
void push_up(int p){
	tree[p]=max(tree[ls(p)],tree[rs(p)]);
}
void build(int p,int pl,int pr){
	tag[p]=0;
	lab[p]=INF;
	if(pl==pr){
		tree[p]=a[pl];
		return;
	}
	int mid=(pl+pr)>>1;
	build(ls(p),pl,mid);
	build(rs(p),mid+1,pr);
	push_up(p);
}
void addtag(int p,int pl,int pr,int d){
	tag[p]+=d;
	tree[p]+=d;
}
void push_down(int p,int pl,int pr){
	if(tag[p]){
		int mid=(pl+pr)>>1;
		addtag(ls(p),pl,mid,tag[p]);
		addtag(rs(p),mid+1,pr,tag[p]);
		tag[p]=0;
	}
}
void update(int p,int pl,int pr,int l,int r,int d){
	if(l<=pl&&pr<=r){
		addtag(p,pl,pr,d);
		return;
	}
	push_down(p,pl,pr);
	int mid=(pl+pr)>>1;
	if(l<=mid) update(ls(p),pl,mid,l,r,d);
	if(r>mid)  update(rs(p),mid+1,pr,l,r,d);
	push_up(p);
}
void spe_add(int p,int d){
	lab[p]=d;
	tree[p]=d;
}
void spe_push_down(int p){
	if(lab[p]!=INF){
    spe_add(ls(p),lab[p]);
    spe_add(rs(p),lab[p]);
    lab[p]=INF;
}
}
void change(int p,int pl,int pr,int l,int r,int d){
	if(l<=pl&&pr<=r){
		spe_add(p,d);
		return;
	}
	push_down(p,pl,pr);
	spe_push_down(p);
	int mid=(pl+pr)>>1;
	if(l<=mid) change(ls(p),pl,mid,l,r,d);
	if(r>mid) change(rs(p),mid+1,pr,l,r,d);
	push_up(p);
}
int query(int p,int pl,int pr,int l,int r){
	if(l<=pl&&pr<=r){
		return tree[p];
	}
	push_down(p,pl,pr);
	int res=INF;
	int mid=(pl+pr)>>1;
	if(l<=mid) res=max(res,query(ls(p),pl,mid,l,r));
	if(r>mid) res=max(res,query(rs(p),mid+1,pr,l,r));
	return res;
}
signed main()
{
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++){
    	scanf("%lld",&a[i]);
	}
	build(1,1,n);
	for(int i=1;i<=m;i++){
		int x;
		scanf("%lld",&x);
		if(x==1){
			int l,r,c;
			scanf("%lld%lld%lld",&l,&r,&c);
			change(1,1,n,l,r,c);
		}
		else if(x==2){
			int y,k,c;
			scanf("%lld%lld%lld",&y,&k,&c);
			update(1,1,n,y,k,c);
		}
		else{
			int y,k;
			scanf("%lld%lld",&y,&k);
			cout<<query(1,1,n,y,k);
			puts("");
		}
	}
	return 0;
}

2024/4/6 16:05
加载中...