随笔- 181  文章- 2  评论- 0  阅读- 6804 

因为洛谷出现UE在acwing提交,输入格式略有修改

#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
const int N = 500010;
int n,q;
int a[N];
struct info
{
	int sum,lmax,rmax,maxn;
};
info operator + (const info& l,const info& r)
{
	info a;
	a.sum = l.sum + r.sum;
	a.lmax = max(l.lmax,l.sum+r.lmax);
	a.rmax = max(r.rmax,r.sum+l.rmax);
	a.maxn = max({l.maxn, r.maxn, a.lmax, a.rmax, l.rmax+r.lmax});
	return a;
}
struct node
{
	int l,r;
	info val;
}tr[N<<2];
void pushup(int p)
{
	tr[p].val = tr[p<<1].val + tr[p<<1|1].val;
}
void build(int l,int r,int p)
{
	tr[p].l = l,tr[p].r = r;
	if(l==r)
	{
		tr[p].val = {a[l],a[l],a[l],a[l]};
		return ;
	}
	int m = (l+r)/2;
	build(l,m,p<<1);
	build(m+1,r,p<<1|1);
	pushup(p);
}
void update(int x,int d,int p)
{
	int l = tr[p].l, r = tr[p].r;
	if(l==r)
	{
		tr[p].val = {d,d,d,d};
		return ;
	}
	int m = (l+r)/2;
	if(x<=m) update(x,d,p<<1);
	else update(x,d,p<<1|1);
	pushup(p);
}
info query(int x,int y,int p)
{
	int l = tr[p].l,r = tr[p].r;
	if(x==l&&r==y) return tr[p].val;
	info ans;
	int m = (l+r)/2;
	if(y<=m) return query(x,y,p<<1);
	else if(x>m) return query(x,y,p<<1|1);
	else return query(x,m,p<<1)+query(m+1,y,p<<1|1);
}
void solve()
{
	cin>>n>>q;
	for(int i=1;i<=n;++i) cin>>a[i];
	build(1,n,1);
	//cin>>q;
	for(int i=1;i<=q;++i)
	{
		int op;
		cin>>op;
		if(op==2)
		{
			int x,d;
			cin>>x>>d;
			update(x,d,1);
		}
		else
		{
			int x,y;
			cin>>x>>y;
			if(x>y) swap(x,y);
			auto res = query(x,y,1);
			cout<<res.maxn<<'\n';
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T=1;
	//cin>>T;
	while(T--)
	{
		solve();
	}
}


 posted on   ruoye123456  阅读(3)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示