A2_Zenith @ 2023-07-13 20:35:13
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdlib>
#include<iomanip>
#include<map>
#define rep(i,n) for(int j=1;j<=n;j++) cout<<a[j];
#define int long long
#define double long double
#define pii pair<int,int>
#define ls(x) x<<1
#define rs(x) x<<1|1
using namespace std;
const int mod=1000000007;
int p=19260817;
const int maxn=500007;
//No,commander.
int n,m;
int a[500007];
struct node {
int lm,rm,mx,sum;
}d[maxn<<2];
void pushup(node &p,node l,node r){
p.sum=l.sum+r.sum;
p.lm=max(l.lm,l.sum+r.lm);
p.rm=max(r.rm,r.sum+l.rm);
int u=max(l.mx,r.mx);
p.mx=max(u,l.rm+r.lm);
}
void build(int p,int s,int t){
if(s==t){
d[p]={a[s],a[s],a[s],a[s]};
return;
}
int m=s+t>>1;
build(ls(p),s,m);
build(rs(p),m+1,t);
pushup(d[p],d[ls(p)],d[rs(p)]);
}
void upd(int x,int p,int s,int t,int k){
if(x==s&&s==t){
d[p]={k,k,k,k};
return;
}
int mid=(s+t)>>1;
if(x<=mid)upd(x,ls(p),s,mid,k);
else upd(x,rs(p),mid+1,t,k);
pushup(d[p],d[ls(p)],d[rs(p)]);
return;
}
node query(int p,int s,int t,int l,int r){
if(l<=s&&t<=r){
return d[p];
}
int mid=s+t>>1;
cout<<s<<" "<<mid<<" "<<t<<endl;
node res;
if(r<=mid)res=query(ls(p),s,m,l,r);
else if(l>mid)res=query(rs(p),m+1,t,l,r);
else{
node ll=query(p,s,t,l,mid);
node rr=query(p,s,t,mid+1,r);
pushup(res,ll,rr);
}
return res;
}
signed main(){
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
build(1,1,n);
for(int i=1;i<=m;i++){
int id;
cin>>id;
if(id==1){
int a,b;
cin>>a>>b;
if(a>b)swap(a,b);
cout<<query(1,1,n,a,b).mx<<endl;
}
else{
int p,s;
cin>>p>>s;
upd(p,1,1,n,s);
}
}
}
by A2_Zenith @ 2023-07-13 20:49:37
rt
rt
rt
rt
rt
rt
by Nemonade @ 2023-07-13 20:51:58
query里面逻辑混乱不堪
by Nemonade @ 2023-07-13 20:52:58
@2338bitexplo 我甚至难以想象你是在什么精神状态下写出来的
by A2_Zenith @ 2023-07-13 20:55:12
@Nemonade
(悲
by Nemonade @ 2023-07-13 20:56:47
但是好像是对的(
by A2_Zenith @ 2023-07-16 19:15:24
query递归部分写错变量名,现已改正并AC。
此帖结。