数据结构(线段树):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 between -10000 and 10000. On this sequence you have to apply M (M <= 50000) operations:
modify the i-th element in the sequence or for given x y print max{Ai + Ai+1 + .. + Aj | x<=i<=j<=y }.
Input
The first line of input contains an integer N. The following line contains N integers, representing the sequence A1..AN.
The third line contains an integer M. The next M lines contain the operations in following form:
0 x y: modify Ax into y (|y|<=10000).
1 x y: print max{Ai + Ai+1 + .. + Aj | x<=i<=j<=y }.
Output
For each query, print an integer as the problem required.
Example
- Input:
- 4
- 1 2 3 4
- 4
- 1 1 3
- 0 3 -3
- 1 2 4
- 1 3 3
- Output:
- 6
- 4
- -3
- #include <iostream>
- #include <cstring>
- #include <cstdio>
- using namespace std;
- const int maxn=;
- const int INF=;
- int n,Q,a[maxn];
- struct Node{
- int lx,rx,mx,sum;
- Node(int _lx=-INF,int _rx=-INF,int _mx=-INF){
- lx=_lx;rx=_rx;mx=_mx;
- }
- }T[maxn<<];
- void Push_up(Node &x,Node l,Node r){
- x.sum=l.sum+r.sum;
- x.lx=max(l.lx,l.sum+r.lx);
- x.rx=max(r.rx,r.sum+l.rx);
- x.mx=max(max(l.mx,r.mx),l.rx+r.lx);
- }
- void Build(int x,int l,int r){
- if(l==r){
- T[x].lx=T[x].rx=max(a[l],);
- T[x].mx=T[x].sum=a[l];
- return;
- }
- int mid=(l+r)>>;
- Build(x<<,l,mid);
- Build(x<<|,mid+,r);
- Push_up(T[x],T[x<<],T[x<<|]);
- }
- void Modify(int x,int l,int r,int g){
- if(l==r){
- T[x].lx=T[x].rx=max(a[l],);
- T[x].mx=T[x].sum=a[l];
- return;
- }
- int mid=(l+r)>>;
- if(mid>=g)Modify(x<<,l,mid,g);
- else Modify(x<<|,mid+,r,g);
- Push_up(T[x],T[x<<],T[x<<|]);
- }
- Node Query(int x,int l,int r,int a,int b){
- if(l>=a&&r<=b)
- return T[x];
- int mid=(l+r)>>;
- Node L,R,ret;
- if(mid>=a)L=Query(x<<,l,mid,a,b);
- if(mid<b)R=Query(x<<|,mid+,r,a,b);
- Push_up(ret,L,R);
- return ret;
- }
- int main(){
- scanf("%d",&n);
- for(int i=;i<=n;i++)
- scanf("%d",&a[i]);
- Build(,,n);
- scanf("%d",&Q);
- int tp,x,y;
- while(Q--){
- scanf("%d%d%d",&tp,&x,&y);
- if(!tp)
- a[x]=y,Modify(,,n,x);
- else
- printf("%d\n",Query(,,n,x,y).mx);
- }
- return ;
- }
- 水题。
数据结构(线段树):SPOJ GSS3 - Can you answer these queries III的更多相关文章
- 线段树 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[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- SPOJ GSS3 Can you answer these queries III ——线段树
[题目分析] GSS1的基础上增加修改操作. 同理线段树即可,多写一个函数就好了. [代码] #include <cstdio> #include <cstring> #inc ...
- SPOJ GSS3 Can you answer these queries III
Time Limit: 330MS Memory Limit: 1572864KB 64bit IO Format: %lld & %llu Description You are g ...
- GSS3 SPOJ 1716. Can you answer these queries III gss1的变形
gss2调了一下午,至今还在wa... 我的做法是:对于询问按右区间排序,利用splay记录最右的位置.对于重复出现的,在splay中删掉之前出现的位置所在的节点,然后在splay中插入新的节点.对于 ...
- SP1716 GSS3 - Can you answer these queries III - 动态dp,线段树
GSS3 Description 动态维护最大子段和,支持单点修改. Solution 设 \(f[i]\) 表示以 \(i\) 为结尾的最大子段和, \(g[i]\) 表示 \(1 \sim i\) ...
- 线段树 SP2713 GSS4 - Can you answer these queries IV暨 【洛谷P4145】 上帝造题的七分钟2 / 花神游历各国
SP2713 GSS4 - Can you answer these queries IV 「题意」: n 个数,每个数在\(10^{18}\) 范围内. 现在有「两种」操作 0 x y把区间\([x ...
- 线段树 SP1043 GSS1 - Can you answer these queries I
SP1043 GSS1 - Can you answer these queries I 题目描述 给出了序列A[1],A[2],-,A[N]. (a[i]≤15007,1≤N≤50000).查询定义 ...
- GSS3 - Can you answer these queries III
题意翻译 nnn 个数, qqq 次操作 操作0 x y把 AxA_xAx 修改为 yyy 操作1 l r询问区间 [l,r][l, r][l,r] 的最大子段和 感谢 @Edgration 提供的 ...
随机推荐
- 零基础学习云计算及大数据DBA集群架构师【预科2015年12月14日周一】
1.第一天比较轻松,上午填表格,录指纹,拍照片,做自我介绍. 2.下午老师简单介绍了一下PC\交换机\路由器\塔式服务器\机架式服务器(1U\2U)\刀片服务器\磁带机 3.班主任陈老师朱老师,预科秦 ...
- MD5 密码破解 碰撞 网站
MD5反向查询网站 http://www.cmd5.com/ 文件MD5值查询网站 http://www.atool.org/file_hash.php 个人对密码破解的理解 1.使用MD5对密码加密 ...
- css3 calc()
概述 CSS函数calc()可以用在任何一个需要<length>的地方.有了calc(),你可以通过计算来决定一个对象的大小和形状. 你还可以在一个calc()内部嵌套另一个calc(). ...
- discuz论坛几种安全策略(一)
安全问题 最近公司准备搭建一个discuz论坛,大头让我调研一下discuz的安全策略,并提出如下几点要求: 1.防止php上传漏洞2.防止大量刷新攻击限制某个IP大量刷新某一页面导致论坛宕机3.防止 ...
- HTML5 文件域+FileReader 分段读取文件并上传到服务器(六)
说明:使用Ajax方式上传,文件不能过大,最好小于三四百兆,因为过多的连续Ajax请求会使后台崩溃,获取InputStream中数据会为空,尤其在Google浏览器测试过程中. 1.简单分段读取文件为 ...
- System.Data.DbType的字符串和数据库中字符串类型对应关系
前两天项目中因为历史原因数据库中的一个字段是varchar类型,在做SQL参数化处理时候默认都是DbType.String, 免得查询出现数据转换,于是做类型一致,搜了下对应关系还没找到,只好自己打开 ...
- Android Parcelable Trans byte[]
思路: http://stackoverflow.com/questions/10898116/make-custom-parcelable-containing-byte-array 谢谢, 这位外 ...
- CI 笔记2,(命令规范等)
调试模式开启,$this->output->enable_profiler(TRUE); 保留字,不能和控制器重名,有3个,CI_Controller ,Default, index.这三 ...
- Ojbect-C2 3、NSArray和NSMutableArray数组的使用
Adopted Protocols NSCoding encodeWithCoder: initWithCoder: NSCopying copyWithZone: NSMutableCopying ...
- Xcode4.4中,代码无法高亮、无法自动补全
1.代码无法高亮显示:2.代码不能自动补全,或者给出提示建议:(当然这个补全的功能我在设置当中是打开的状态)3.新建一个项目,代码还是依然没有高亮显示,但是有补全功能:4.然后我就在网络上搜索了相关的 ...