题意:

单点修改,区间最值

思路:

线段树

原题请戳这里

//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LSON l,mid,lson
#define RSON mid+1,r,rson
#define N 500000
#define inf 0x3fffffff
using namespace std;
int n,m,jy,xx,yy,RANS,ANS;
int tree[N*4],lmax[N*4],rmax[N*4],maxx[N*4],sum[N*4];
void push_up(int pos,int lson,int rson){
sum[pos]=sum[lson]+sum[rson];
rmax[pos]=max(rmax[rson],sum[rson]+rmax[lson]);
lmax[pos]=max(lmax[lson],lmax[rson]+sum[lson]);
maxx[pos]=max(maxx[lson],max(maxx[rson],rmax[lson]+lmax[rson]));
}
void build(int l,int r,int pos){
if(l==r){
scanf("%d",&tree[pos]);
lmax[pos]=rmax[pos]=sum[pos]=maxx[pos]=tree[pos];
return;
}
int mid=(l+r)/2,lson=pos<<1,rson=pos<<1|1;
build(LSON);build(RSON);
push_up(pos,lson,rson);
}
void query(int l,int r,int pos){
if(l>=xx&&r<=yy){
ANS=max(ANS,max(maxx[pos],RANS+lmax[pos]));
RANS=max(rmax[pos],RANS+sum[pos]);
return;
}
int mid=(l+r)/2,lson=pos<<1,rson=pos<<1|1;
if(mid<xx)query(RSON);
else if(mid>=yy)query(LSON);
else query(LSON),query(RSON);
}
void update(int l,int r,int pos){
if(l==r){
lmax[pos]=rmax[pos]=sum[pos]=maxx[pos]=tree[pos]=yy;
return;
}
int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1;
if(mid<xx)update(RSON);
else update(LSON);
push_up(pos,lson,rson);
}
int main(){
scanf("%d%d",&n,&m);
build(1,n,1);
while(m--){
scanf("%d%d%d",&jy,&xx,&yy);
if(jy==1){
if(xx>yy)swap(xx,yy);
ANS=RANS=-inf;
query(1,n,1);
printf("%d\n",ANS);
}
else
update(1,n,1);
}
}

最新文章

  1. 【详细教程】论android studio中如何申请百度地图新版Key中SHA1值
  2. Excel画的图复制到Word中变形的解决办法
  3. Spark&amp;Hadoop:scala编写spark任务jar包,运行无法识别main函数,怎么办?
  4. ABAP 数值类型转换
  5. js九宫格的碰撞检测
  6. Node.js +Express+MongoDB+mogoose+ejs+bootstrap+jquery
  7. 微软职位内部推荐-Software Engineer II-News
  8. php 数组去除空值
  9. C#学习日志 day 4 ------ 类相关---this指针以及相关关键字
  10. [IDEs]Eclipse设置花括号样式
  11. 几种访问其他域swf文件,或本地浏览器运行环境【安全沙箱】冲突解决方法
  12. PendingIntent、Notification常用方法
  13. c#之异步Socket通信
  14. Servlet线程
  15. Java内存管理的进一步理解-模拟过程图解
  16. HTTPS笔记:使用 SSLEngine 为 aioserver 服务器提供 SSL 访问支持
  17. .net core 中的 DependencyInjection - IOC
  18. Codeforces 1136 - A/B/C/D/E - (Done)
  19. java使用Base64编码
  20. Android 桌面部件

热门文章

  1. Eclipse之注释部分代码
  2. PCL的学习必要性、重要性、意义及最初——持续修改中
  3. Higher-Order Functions and Lambdas
  4. PowerShell 解决红字一闪而过问题
  5. webpack学习(六)—webpack+react+es6(第3篇)
  6. Django 路由视图FBV/CBV
  7. JQuery的click,trigger触发a标签的click事件无效的问题分析
  8. 系统和帮助-Linux基础知识
  9. Linux 常用密令总结 ------随用随记吧
  10. jQuery源码分析 开篇(一)