蒟蒻求助 60分 #7~10 WA
查看原帖
蒟蒻求助 60分 #7~10 WA
1011275
Glass_S楼主2023/9/17 20:36
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#include<cstdio>
#include<ctime>
#include<stack>
#define int long long
#define lp (p<<1)
#define rp (p<<1|1)
#define mid ((l+r)>>1)
#define N 1000005
#define M N<<2
using namespace std;
int n,m,x,y,op,bj[M];
int a[N],maxx[M],add[M],vis[M];
int re()
{
	int x=0,p=1;
	char y=getchar();
	for(;y>'9'||y<'0';y=getchar())
		if(y=='-')
			p=-p;
	for(;y>='0'&&y<='9';y=getchar())
		x=x*10+y-'0';
	return x*p;
}
void wr(int x)
{
	if(x<0)
		x=-x,putchar('-');
	if(x>9)
		wr(x/10);
	putchar(x%10+'0');
}
void Push_up(int p){
	maxx[p]=max(maxx[lp],maxx[rp]);
}
void Push_down(int l,int r,int p){
	if(bj[p]){
		maxx[rp]=vis[p];
		maxx[lp]=vis[p];
		vis[lp]=vis[p];
		vis[rp]=vis[p];
		vis[p]=0;
		bj[p]=0;
		bj[rp]=1;
		bj[lp]=1;
	}
	if(add[p]){
		maxx[lp]+=add[p];
		maxx[rp]+=add[p];
		add[lp]+=add[p];
		add[rp]+=add[p];
		add[p]=0;
	}
}
void Build(int l,int r,int p){
	if(l==r){
		maxx[p]=a[l];
		return;
	}
	Build(l,mid,lp);
	Build(mid+1,r,rp);
	Push_up(p);
}
void Add(int al,int ar,int l,int r,int p,int k){
	if(al<=l&&ar>=r){
		maxx[p]+=k;
		add[p]+=k;
		return;
	}
	if(bj[p]||add[p])
	    Push_down(l,r,p);
	if(al<=mid)
	    Add(al,ar,l,mid,lp,k);
	if(ar>mid)
	    Add(al,ar,mid+1,r,rp,k);
	Push_up(p);
}
void Change(int cl,int cr,int l,int r,int p,int k){
	if(cl<=l&&cr>=r){
		maxx[p]=k;
		bj[p]=1;
		vis[p]=k;
		add[p]=0;
		return;
	}
	if(bj[p]||add[p])
	    Push_down(l,r,p);
	if(cl<=mid)
	    Change(cl,cr,l,mid,lp,k);
	if(cr>mid)
	    Change(cl,cr,mid+1,r,rp,k);
	Push_up(p);
}
int Max(int ml,int mr,int l,int r,int p){
	if(ml<=l&&mr>=r)
		return maxx[p];
	if(bj[p]||add[p])
	    Push_down(l,r,p);
	int ans=-1e18;
	if(ml<=mid)
	    ans=max(ans,Max(ml,mr,l,mid,lp));
	if(mr>mid)
	    ans=max(ans,Max(ml,mr,mid+1,r,rp));
	return ans;
}
signed main()
{
    n=re(),m=re();
    for(int i=1;i<=n;i++)
        a[i]=re();
    Build(1,n,1);
    while(m--){
    	op=re(),x=re(),y=re();
    	if(op==1){
    		int k=re();
    		Change(x,y,1,n,1,k);
		}
		else if(op==2){
			int k=re();
			Add(x,y,1,n,1,k);
		}
    	else if(op==3){
    		wr(Max(x,y,1,n,1));putchar('\n');
		}
	}
	return 0;
}
2023/9/17 20:36
加载中...