求调
查看原帖
求调
1072786
jq_ll19802楼主2024/9/27 19:18
#include<bits/stdc++.h>
#define sc(x) scanf("%lld",&x)

using namespace std;

long long n,m,t[4000005],l[4000005],r[4000005],a[4000005],la[4000005],g[4000005],b,c,d,op,mid,da;

void js(int x,int L,int R)
{
	if(L>R)return;
	if(L==R)
	{
		t[x]=a[L];
		l[x]=L;
		r[x]=R;
		return;
	}
	js(x*2,L,(L+R)/2);
	js(x*2+1,(L+R)/2+1,R);
	t[x]=max(t[x*2],t[x*2+1]);
	l[x]=L;
	r[x]=R;
}

void gz(int x)
{
	if(l[x]!=r[x])
	{
		if(g[x]!=-5000000000000000)
		{
			g[x*2]=g[x];
			g[x*2+1]=g[x];
			la[x*2]=0;
			la[x*2+1]=0;
			t[x*2]=g[x];
			t[x*2+1]=g[x];
			g[x]=-5000000000000000;
		}
		if(la[x]!=0)
		{
			la[x*2]+=la[x];
			la[x*2+1]+=la[x];
			t[x*2]+=la[x];
			t[x*2+1]+=la[x];
			la[x]=0;
		}
	}
	else
	{
		if(g[x]!=-5000000000000000)
		a[x]=g[x]+la[x];
		else a[x]+=la[x];
		la[x]=0;
		g[x]=-5000000000000000;
		t[x]=a[x];
	}
}

void xg1(int x,int L,int R,long long v)
{
	if(l[x]>R||r[x]<L)return;
	if(l[x]>=L&&r[x]<=R)
	{
		g[x]=v;
		la[x]=0;
		t[x]=v;
		return;
	}
	xg1(x*2,L,R,v);
	xg1(x*2+1,L,R,v);
	t[x]=max(t[x],v);
}

void xg2(int x,int L,int R,long long v)
{
	if(l[x]>R||r[x]<L)return;
	if(l[x]>=L&&r[x]<=R)
	{
		la[x]+=v;
		t[x]+=v;
		return;
	}
	gz(x);
	xg2(x*2,L,R,v);
	xg2(x*2+1,L,R,v);
	t[x]=max(t[x*2],t[x*2+1]);
}

long long cx(int x,int L,int R) 
{
	if(l[x]>R||r[x]<L)return -5000000000000000;
	if(l[x]==r[x])
	{
		return t[x];
	}
	if(l[x]>=L&&r[x]<=R)
	{
		return t[x];
	}
	gz(x);
	da=cx(x*2,L,R);
	da=max(da,cx(x*2+1,L,R));
	t[x]=max(t[x*2],t[x*2+1]);
	return da;
}

int main()
{
	sc(n);
	
	sc(m);
	
	for(int i=1;i<=n;i++)
	{
		sc(a[i]);
	}
	
	for(int i=0;i<=4*n;i++)
	{
		g[i]=-5000000000000000;
	}
	
	js(1,1,n);
	
	for(int i=1;i<=m;i++)
	{
		sc(op);
		if(op==1) 
		{
			sc(b);
			sc(c);
			sc(d);
			xg1(1,b,c,d);
		} 
		if(op==2)
		{
			sc(b);
			sc(c);
			sc(d);
			xg2(1,b,c,d);
		}
		if(op==3)
		{
			sc(b);
			sc(c);
			printf("%lld\n",cx(1,b,c));
		}
	}
	
	return 0;
}
2024/9/27 19:18
加载中...