spoj1716 Can you answer these queries III
(分析见正睿2018.10.1笔记)
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
struct node {
int pre,sur,ans,sum;
};
node d[];
inline node work(node x,node y){
node res;
res.sum=x.sum+y.sum;
res.pre=max(x.pre,x.sum+y.pre);
res.sur=max(y.sur,y.sum+x.sur);
res.ans=max(max(x.ans,y.ans),x.sur+y.pre);
return res;
}
inline void update(int le,int ri,int wh,int pl,int k){
if(le==ri){
d[wh].pre=d[wh].sur=d[wh].ans=d[wh].sum=k; return;
}
int mid=(le+ri)>>;
if(mid>=pl)update(le,mid,wh<<,pl,k);
else update(mid+,ri,wh<<|,pl,k);
d[wh]=work(d[wh<<],d[wh<<|]);
return;
}
inline node q(int le,int ri,int wh,int x,int y){
if(le>=x&&ri<=y){
return d[wh];
}
int mid=(le+ri)>>,cnt=;
node a,b;
if(mid>=x)cnt+=,a=q(le,mid,wh<<,x,y);
if(mid<y)cnt+=,b=q(mid+,ri,wh<<|,x,y);
if(cnt==)return a;
if(cnt==)return b;
return work(a,b);
}
int main(){
int n,m,i,j,k,x,y;
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d",&x);
update(,n,,i,x);
}
scanf("%d",&m);
for(i=;i<=m;i++){
scanf("%d%d%d",&k,&x,&y);
if(k==){
update(,n,,x,y);
}else {
printf("%d\n",q(,n,,x,y).ans);
}
}
return ;
}
spoj1716 Can you answer these queries III的更多相关文章
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- GSS3 SPOJ 1716. Can you answer these queries III gss1的变形
gss2调了一下午,至今还在wa... 我的做法是:对于询问按右区间排序,利用splay记录最右的位置.对于重复出现的,在splay中删掉之前出现的位置所在的节点,然后在splay中插入新的节点.对于 ...
- 数据结构(线段树):SPOJ GSS3 - Can you answer these queries III
GSS3 - Can you answer these queries III You are given a sequence A of N (N <= 50000) integers bet ...
- 线段树 SP1716 GSS3 - Can you answer these queries III
SP1716 GSS3 - Can you answer these queries III 题意翻译 n 个数,q 次操作 操作0 x y把A_xAx 修改为yy 操作1 l r询问区间[l, r] ...
- 「 SPOJ GSS3 」 Can you answer these queries III
# 题目大意 GSS3 - Can you answer these queries III 需要你维护一种数据结构,支持两种操作: 单点修改 求一个区间的最大子段和 # 解题思路 一个区间的最大子段 ...
- Can you answer these queries III
Can you answer these queries III 题目:洛谷 SPOJ [题目描述] 给定长度为N的数列A,以及M条指令,每条指令可能是以下两种之一: 1.“0 x y”,把A[x]改 ...
- Can you answer these queries III(线段树)
Can you answer these queries III(luogu) Description 维护一个长度为n的序列A,进行q次询问或操作 0 x y:把Ax改为y 1 x y:询问区间[l ...
- [SPOJ1716] GSS3 - Can you answer these queries III
线段树操作. 维护一个区间最大连续子段和,左最大连续子段和,右最大连续子段和即可. 最后不知道怎么搞,query的时候返回了个结构体. #include <cstdio> #include ...
- SPOJ GSS3 Can you answer these queries III
Time Limit: 330MS Memory Limit: 1572864KB 64bit IO Format: %lld & %llu Description You are g ...
随机推荐
- cmd命令之查看进程到杀掉进程
1. cmd命令查看当前进程 netstat -ano | findstr “port”
- thinkphp3.0中ajax的发送
系统支持任何的AJAX类库,Action类提供了ajaxReturn方法用于 AJAX调用后返回数据给客户端.并且支持JSON.XML和EVAL三种方式给客户端接受数据,通过配置DEFAULT_AJA ...
- 幸运数字(数位dp)
个人心得:数位dp处理起来是真的麻烦,本来动态规划就够头疼的了,菜的一批. 来看这个题目吧,题目在下面. 把题目变成可以求得就是求前n个数中1-n*9的情况的总和,所以用dp[i][j],表示前i个数 ...
- JavaScript6 新语法 let 有什么优势
最近看国外的前端代码时,发现ES6的新特性已经相当普及,尤其是 let,应用非常普遍 虽然 let 的用法与 var 相同,但不管是语法语义上,还是性能上,都提升了很多,下面就从这两方面对比一下 语法 ...
- UML类图与类的关系详解【转】
在画类图的时候,理清类和类之间的关系是重点. 类的关系有泛化(Generalization).实现(Realization).依赖(Dependency)和关联(Association).其中关联又分 ...
- Spark Shuffle大揭秘
什么是Shuffle: Shuffle中文翻译为“洗牌”,需要Shuffle的关键原因是某种具有共同特征的数据需要最终汇聚到一个计算节点上进行计算. Shuffle面临的问题: 1. 数据量非常大: ...
- python3 之 格式化json
import json json_string = None with open("json_file.json") as f: json_string = f.read() tr ...
- 寻找php.ini之旅
/usr/local/php-fpm/lib/php.ini 可以通过phpinfo()来查看 https://www.cnblogs.com/ChineseMoonGod/p/6474772.htm ...
- JSF结合Spring 引入ViewScope
当JSF项目的faceConfig中配置了Spring的配置代码 <application> <el-resolver>org.springframework.web.jsf. ...
- UVA548(二叉树遍历)
You are to determine the value of the leaf node in a given binary tree that is the terminal node of ...