跳到正文

个人记录

【清华集训2015】V

PPL_约 6 分钟
原文
文章信息与版本

文章信息

发布
2020年1月19日
收录
2025年12月17日
更新
2026年11月7日
篇幅
约 6 分钟

版本

  1. v2当前
  2. v1

前言

清华大佬WZD\text{WZD}课件中出现的题

先膜一发OneInDark巨佬\text{OneInDark巨佬}

再膜一发C202044zxy妹儿\text{C202044zxy妹儿}

有任何不懂的都可以看巨佬的博客↑,鸽的理由

题目

UOJ

正题

今天(2020..01.19)超级困,鸽了~

今天(2020..01.20)比较困,鸽了~

代码

C++
//12252024832524
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;
const int MAXN = 500005;
const LL INF = 0x3f3f3f3f3f3f3f3fll;
int n,m;
LL a[MAXN];

LL Read()
{
	LL x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
void Put1(LL x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
void Put(LL x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x);
	if(c >= 0) putchar(c);
}
template <typename T>T Max(T x,T y){return x > y ? x : y;}
template <typename T>T Min(T x,T y){return x < y ? x : y;}
template <typename T>T Abs(T x){return x < 0 ? -x : x;}

struct node
{
	int l,r;
	LL x,y,tx,ty;//当前的与历史的
	node(){}
	node(int l1,int r1,LL x1,LL y1,LL tx1,LL ty1){
		l = l1;
		r = r1;
		x = x1;
		y = y1;
		tx = tx1;
		ty = ty1;
	}
}t[MAXN << 2];
node Merge(node a,node b)
{
	return node(a.l,a.r,Max(a.x+b.x,-INF),Max(a.y+b.x,b.y),Max(a.tx,a.x+b.tx),Max(a.ty,Max(a.y+b.tx,b.ty)));
}
void down(int x)
{
	if(t[x].l == t[x].r) return;
	t[x<<1] = Merge(t[x<<1],t[x]);
	t[x<<1|1] = Merge(t[x<<1|1],t[x]);
	t[x] = node(t[x].l,t[x].r,0,0,0,0);
}
void Build(int x,int l,int r)
{
	t[x] = node(l,r,0,0,0,0);
	if(l == r) return;
	int mid = (l+r) >> 1;
	Build(x<<1,l,mid);
	Build(x<<1|1,mid+1,r);
}
void change(int x,int l,int r,node v)
{
	if(t[x].r < l || t[x].l > r) return;
	if(t[x].l >= l && t[x].r <= r)
	{
		t[x] = Merge(t[x],v);
		return;
	}
	down(x);
	change(x<<1,l,r,v);
	change(x<<1|1,l,r,v);
}
node query(int x,int q)
{
	if(t[x].l == t[x].r) return t[x];
	down(x);
	if(q <= t[x<<1].r) return query(x<<1,q);
	else return query(x<<1|1,q);
}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n = Read();
	m = Read();
	for(int i = 1;i <= n;++ i) a[i] = Read();
	Build(1,1,n);
	for(; m ;-- m)
	{
		int opt = Read();
		if(opt == 1)//区间加
		{
			int l = Read(),r = Read(),x = Read();
			change(1,l,r,node(0,0,x,-INF,x,-INF));
		}
		else if(opt == 2)//区间减
		{
			int l = Read(),r = Read(),x = Read();
			change(1,l,r,node(0,0,-x,0,-x,0));
		}
		else if(opt == 3)//区间赋值
		{
			int l = Read(),r = Read(),x = Read();
			change(1,l,r,node(0,0,-INF,x,-INF,x));
		}
		else if(opt == 4)//单点询问
		{
			int x = Read();
			node ans = query(1,x);
			Put(Max(a[x]+ans.x,ans.y),'\n');
		}
		else if(opt == 5)//历史最大值
		{
			int x = Read();
			node ans = query(1,x);
			Put(Max(a[x]+ans.tx,ans.ty),'\n');
		}
	}
	return 0;
}

Thanks to XEZThanks\ to\ XEZ

原文