因为洛谷出现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();
}
}
标签:info,typedef,these,sum,rmax,int,lmax,queries,answer
From: https://www.cnblogs.com/ruoye123456/p/18440549