传送门

(分析见正睿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的更多相关文章

  1. 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 ...

  2. GSS3 SPOJ 1716. Can you answer these queries III gss1的变形

    gss2调了一下午,至今还在wa... 我的做法是:对于询问按右区间排序,利用splay记录最右的位置.对于重复出现的,在splay中删掉之前出现的位置所在的节点,然后在splay中插入新的节点.对于 ...

  3. 数据结构(线段树):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 ...

  4. 线段树 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] ...

  5. 「 SPOJ GSS3 」 Can you answer these queries III

    # 题目大意 GSS3 - Can you answer these queries III 需要你维护一种数据结构,支持两种操作: 单点修改 求一个区间的最大子段和 # 解题思路 一个区间的最大子段 ...

  6. Can you answer these queries III

    Can you answer these queries III 题目:洛谷 SPOJ [题目描述] 给定长度为N的数列A,以及M条指令,每条指令可能是以下两种之一: 1.“0 x y”,把A[x]改 ...

  7. 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 ...

  8. [SPOJ1716] GSS3 - Can you answer these queries III

    线段树操作. 维护一个区间最大连续子段和,左最大连续子段和,右最大连续子段和即可. 最后不知道怎么搞,query的时候返回了个结构体. #include <cstdio> #include ...

  9. SPOJ GSS3 Can you answer these queries III

    Time Limit: 330MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Description You are g ...

随机推荐

  1. Shell编程-运算符

    1.declare命令 declare声明变量类型:declare [+/-][选项] 变量名 -:给变量设定类型属性 +:取消变量的类型属性 -a:将变量声明为数组型 -i:整数型 -x:环境变量 ...

  2. 201621123014《Java程序设计》第十二周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 面向系统综合设计-图书馆管理系统或购物车 使用流与文件改造你的图书馆管理系统或购物车. 2.1 简述如何 ...

  3. PHP Smarty template for website

    /****************************************************************************** * PHP Smarty templat ...

  4. Magic Index 寻找数组中A[i]=i的位置(原题转自微信号待字闺中)

    有一个有意思的题目叫做Magic Index:给定一个数组A,其中有一个位置被称为Magic Index,含义是:如果i是Magic Index,则A[i] = i.假设A中的元素递增有序.且不重复, ...

  5. ftp上传下载 java FTPClient (zhuan)

    项目需要,网上搜了搜,很多,但问题也不少,估计转来转去,少了不少东西,而且也情况也不太一样.没办法,只能自己去写一个. 一,    安装sserv-u ftp服务器 版本10.1.0.1 我所设服务器 ...

  6. wpf控件提示Value ‘’ can not convert

    我们在对控件的ErrorTemplate设置后,有时会出现Value '' can not convert. 为什么会出现呢? 原因:如果控件的输入值和null不能转换(比如控件要求的是int或flo ...

  7. JavaWeb开发Eclipse环境配置--史上最详细的教程

    [前言] JSP本身是JavaWeb中的知识,但是在学习Android网络时,必然要涉及到与服务器之间的交互,所以学一下JSP以及其他JavaWeb的内容还是很有必要的,至少能明白程序在访问服务器时, ...

  8. install 命令

    install命令的作用是安装或升级软件或备份数据,它的使用权限是所有用户.install命令和cp命令类似,都可以将文件/目录拷贝到指定的地点.但是,install允许你控制目标文件的属性.inst ...

  9. git教程(远程仓库和管理分支)

    在github上新建了一个仓库,然后相与本地的仓库联系起来 $ Git remote add origin https://github.com/liona329/learngit.git fatal ...

  10. Oracle user,role,profile常规操作--用户,权限,角色,配置文件

    Oracle user,role,profile常规操作--用户,权限,角色,配置文件 1 权限查询 1查看所有用户 SQL> select username,account_status,lo ...