王炸拆开打 @ 2020-10-07 21:29:49
RT
#include<iostream>
#include<cstdio>
#define LL long long
using namespace std;
LL a[400001],n,m,P=0x7f7f7f7f7f7f7f7f;
struct tree{
int l,r,sum,m,lm,rm;
#define l(x) t[x].l
#define rm(x) t[x].rm
#define lm(x) t[x].lm
#define r(x) t[x].r
#define m(x) t[x].m
#define sum(x) t[x].sum
}t[400004];
void spread(int p){
sum(p)=sum(p*2)+sum(p*2+1);
lm(p)=max(sum(p*2)+lm(p*2+1),lm(p*2));
rm(p)=max(sum(p*2+1)+rm(p*2),rm(p*2+1));
m(p)=max(max(m(p*2),m(p*2+1)),rm(p*2)+lm(p*2+1));
}
void build(int l,int r,int p){
l(p)=l;r(p)=r;
if(l==r) {
sum(p)=lm(p)=rm(p)=m(p)=a[l];
return;
}
int mid=(l+r)>>1;
build(l,mid,p*2);
build(mid+1,r,p*2+1);
spread(p);
}
void change(int p,int x,int c){
if(l(p)==r(p)){
sum(p)=lm(p)=rm(p)=m(p)=c;
return;
}
int mid=(l(p)+r(p))>>1;
if(mid>=x) change(p*2,x,c);
else change(p*2+1,x,c);
spread(p);
}
tree ask(int p,int l,int r){
if(l(p)>=l&&r(p)<=r) return sum(p);
spread(p);
int mid=(l(p)+r(p))>>1;
if(l>mid) return ask(p*2,l,r);
else if(r<=mid) return ask(p*2+1,l,r);
else{
tree x=ask(p*2,l,r),y=ask(p*2+1,l,r),ans;
sum(ans)=sum(x)+sum(y);
lm(ans)=max(sum(x)+lm(y),lm(x));
rm(ans)=max(sum(y)+rm(x),rm(y));
m(ans)=max(max(m(x),m(y)),rm(x)+lm(y));
return ans;
}
}
int main(){
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
build(1,n,1);
for(int e=1;e<=m;e++){
int si,ti,gi;
scanf("%d%d%d",&si,&ti,&gi);
if(si==1){
if(ti>gi) swap(ti,gi);
tree ans=ask(1,ti,gi);
printf("%lld\n",ans.maxx);
}
else change(1,ti,gi);
}
return 0;
}
by mot1ve @ 2020-10-07 21:35:14
建议放弃线段树
by mot1ve @ 2020-10-07 21:35:27
因为考场上有可能连暴力都打不出来
by 宝硕 @ 2020-10-07 21:37:33
struct tree{
int l,r,sum,m,lm,rm;
#define l(x) t[x].l
#define rm(x) t[x].rm
#define lm(x) t[x].lm
#define r(x) t[x].r
#define m(x) t[x].m
#define sum(x) t[x].sum
}t[400004];
我觉得这里不对。(这什么魔法操作)
by 傅天宇 @ 2020-10-07 21:38:00
直接 define 在外面没事的吧?(不太清楚
by daiarineko @ 2020-10-07 21:42:21
@宝硕 超限了吧(int*500000=超限,这弄个2.4M)
by Wildchesse @ 2020-10-07 21:42:25
请define在struct后(t后面)
by daiarineko @ 2020-10-07 21:43:21
还有,宏定义貌似得放前面
by fzj2007 @ 2020-10-07 22:01:09
@qidirj 放后边也行
by chichichichi @ 2020-10-07 22:08:24
在结构体里宏没问题
by chichichichi @ 2020-10-07 22:23:46
这里错了
tree ask(int p,int l,int r){
if(l(p)>=l&&r(p)<=r) return sum(p);
函数类型是tree