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

  1. Input:
  2. 4
  3. 1 2 3 4
  4. 4
  5. 1 1 3
  6. 0 3 -3
  7. 1 2 4
  8. 1 3 3
  9.  
  10. Output:
  11. 6
  12. 4
  13. -3
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. using namespace std;
  5. const int maxn=;
  6. const int INF=;
  7. int n,Q,a[maxn];
  8.  
  9. struct Node{
  10. int lx,rx,mx,sum;
  11. Node(int _lx=-INF,int _rx=-INF,int _mx=-INF){
  12. lx=_lx;rx=_rx;mx=_mx;
  13. }
  14. }T[maxn<<];
  15.  
  16. void Push_up(Node &x,Node l,Node r){
  17. x.sum=l.sum+r.sum;
  18. x.lx=max(l.lx,l.sum+r.lx);
  19. x.rx=max(r.rx,r.sum+l.rx);
  20. x.mx=max(max(l.mx,r.mx),l.rx+r.lx);
  21. }
  22.  
  23. void Build(int x,int l,int r){
  24. if(l==r){
  25. T[x].lx=T[x].rx=max(a[l],);
  26. T[x].mx=T[x].sum=a[l];
  27. return;
  28. }
  29. int mid=(l+r)>>;
  30. Build(x<<,l,mid);
  31. Build(x<<|,mid+,r);
  32. Push_up(T[x],T[x<<],T[x<<|]);
  33. }
  34.  
  35. void Modify(int x,int l,int r,int g){
  36. if(l==r){
  37. T[x].lx=T[x].rx=max(a[l],);
  38. T[x].mx=T[x].sum=a[l];
  39. return;
  40. }
  41. int mid=(l+r)>>;
  42. if(mid>=g)Modify(x<<,l,mid,g);
  43. else Modify(x<<|,mid+,r,g);
  44. Push_up(T[x],T[x<<],T[x<<|]);
  45. }
  46.  
  47. Node Query(int x,int l,int r,int a,int b){
  48. if(l>=a&&r<=b)
  49. return T[x];
  50. int mid=(l+r)>>;
  51. Node L,R,ret;
  52. if(mid>=a)L=Query(x<<,l,mid,a,b);
  53. if(mid<b)R=Query(x<<|,mid+,r,a,b);
  54. Push_up(ret,L,R);
  55. return ret;
  56. }
  57.  
  58. int main(){
  59. scanf("%d",&n);
  60. for(int i=;i<=n;i++)
  61. scanf("%d",&a[i]);
  62. Build(,,n);
  63. scanf("%d",&Q);
  64. int tp,x,y;
  65. while(Q--){
  66. scanf("%d%d%d",&tp,&x,&y);
  67. if(!tp)
  68. a[x]=y,Modify(,,n,x);
  69. else
  70. printf("%d\n",Query(,,n,x,y).mx);
  71. }
  72. return ;
  73. }
  1. 水题。
  2.  
  3.  

数据结构(线段树):SPOJ GSS3 - Can you answer these queries III的更多相关文章

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

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

  3. SPOJ GSS3 Can you answer these queries III ——线段树

    [题目分析] GSS1的基础上增加修改操作. 同理线段树即可,多写一个函数就好了. [代码] #include <cstdio> #include <cstring> #inc ...

  4. SPOJ GSS3 Can you answer these queries III

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

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

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

  6. SP1716 GSS3 - Can you answer these queries III - 动态dp,线段树

    GSS3 Description 动态维护最大子段和,支持单点修改. Solution 设 \(f[i]\) 表示以 \(i\) 为结尾的最大子段和, \(g[i]\) 表示 \(1 \sim i\) ...

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

  8. 线段树 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).查询定义 ...

  9. 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 提供的 ...

随机推荐

  1. 零基础学习云计算及大数据DBA集群架构师【预科2015年12月14日周一】

    1.第一天比较轻松,上午填表格,录指纹,拍照片,做自我介绍. 2.下午老师简单介绍了一下PC\交换机\路由器\塔式服务器\机架式服务器(1U\2U)\刀片服务器\磁带机 3.班主任陈老师朱老师,预科秦 ...

  2. MD5 密码破解 碰撞 网站

    MD5反向查询网站 http://www.cmd5.com/ 文件MD5值查询网站 http://www.atool.org/file_hash.php 个人对密码破解的理解 1.使用MD5对密码加密 ...

  3. css3 calc()

    概述 CSS函数calc()可以用在任何一个需要<length>的地方.有了calc(),你可以通过计算来决定一个对象的大小和形状. 你还可以在一个calc()内部嵌套另一个calc(). ...

  4. discuz论坛几种安全策略(一)

    安全问题 最近公司准备搭建一个discuz论坛,大头让我调研一下discuz的安全策略,并提出如下几点要求: 1.防止php上传漏洞2.防止大量刷新攻击限制某个IP大量刷新某一页面导致论坛宕机3.防止 ...

  5. HTML5 文件域+FileReader 分段读取文件并上传到服务器(六)

    说明:使用Ajax方式上传,文件不能过大,最好小于三四百兆,因为过多的连续Ajax请求会使后台崩溃,获取InputStream中数据会为空,尤其在Google浏览器测试过程中. 1.简单分段读取文件为 ...

  6. System.Data.DbType的字符串和数据库中字符串类型对应关系

    前两天项目中因为历史原因数据库中的一个字段是varchar类型,在做SQL参数化处理时候默认都是DbType.String, 免得查询出现数据转换,于是做类型一致,搜了下对应关系还没找到,只好自己打开 ...

  7. Android Parcelable Trans byte[]

    思路: http://stackoverflow.com/questions/10898116/make-custom-parcelable-containing-byte-array 谢谢, 这位外 ...

  8. CI 笔记2,(命令规范等)

    调试模式开启,$this->output->enable_profiler(TRUE); 保留字,不能和控制器重名,有3个,CI_Controller ,Default, index.这三 ...

  9. Ojbect-C2 3、NSArray和NSMutableArray数组的使用

    Adopted Protocols NSCoding encodeWithCoder: initWithCoder: NSCopying copyWithZone: NSMutableCopying ...

  10. Xcode4.4中,代码无法高亮、无法自动补全

    1.代码无法高亮显示:2.代码不能自动补全,或者给出提示建议:(当然这个补全的功能我在设置当中是打开的状态)3.新建一个项目,代码还是依然没有高亮显示,但是有补全功能:4.然后我就在网络上搜索了相关的 ...