蒟蒻0pts求条
查看原帖
蒟蒻0pts求条
655089
wch2021楼主2024/11/22 11:11

rt,样例都能过,评测记录

#include<bits/stdc++.h>
#define int __int128
using namespace std;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(!(ch<='9'&&ch>='0'))
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch<='9'&&ch>='0')
	{
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
inline void write(int x)
{
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	if(x>9) write(x/10);
	putchar('0'+x%10);
}
struct node
{
	int mx,mn,ans,lay;
}tr[4000005];
void pu(int u)
{
	tr[u].mn=min(tr[u<<1].mn,tr[u<<1|1].mn);
	tr[u].mx=max(tr[u<<1].mx,tr[u<<1|1].mx);
	tr[u].ans=max(tr[u].mx-tr[u].mn,tr[u<<1].ans+tr[u<<1|1].ans);
}
void build(int l,int r,int u)
{
	if(l==r)
	{
		tr[u].mx=tr[u].mn=read();
		tr[u].ans=0;
		tr[u].lay=0;
		return;
	}
	tr[u].ans=0;
	tr[u].lay=0;
	tr[u].mx=-1e9;
	tr[u].mn=1e9;
	int mid=l+r>>1;
	build(l,mid,u<<1);
	build(mid+1,r,u<<1|1);
	pu(u);
}
void pd(int u)
{
	tr[u<<1].lay+=tr[u].lay;
	tr[u<<1|1].lay+=tr[u].lay;
	tr[u].mx+=tr[u].lay;
	tr[u].mn+=tr[u].lay;
	tr[u<<1].mx+=tr[u].lay;
	tr[u<<1].mn+=tr[u].lay;
	tr[u<<1|1].mx+=tr[u].lay;
	tr[u<<1|1].mn+=tr[u].lay;
	tr[u].lay=0;
}
void upd(int l,int r,int L,int R,int u,int x)
{
	if(L<=l&&r<=R)
	{
		tr[u].mx+=x;
		tr[u<<1].mx+=x;
		tr[u<<1|1].mx+=x;
		tr[u].mn+=x;
		tr[u<<1].mn+=x;
		tr[u<<1|1].mn+=x;
		tr[u<<1].lay+=x;
		tr[u<<1|1].lay+=x;
		return;
	}
	pd(u);
	int mid=l+r>>1;
	if(L<=mid) upd(l,mid,L,R,u<<1,x);
	if(R>mid) upd(mid+1,r,L,R,u<<1|1,x);
	pu(u);
}
signed main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n=read(),q=read();
	build(1,n,1);
	while(q--)
	{
		int l=read(),r=read(),x=read();
		upd(1,n,l,r,1,x);
		write(tr[1].ans);
		putchar('\n');
	}
	return 0;
}
2024/11/22 11:11
加载中...