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的更多相关文章

  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. Writing Your First Test

    Let's say you have an activity layout that represents a welcome screen: <?xml version="1.0&q ...

  2. c++矩阵运算

    优化了一些算法 #pragma once #include <iostream> #include <iomanip> #include <string> #def ...

  3. 10.25 noip模拟试题

    今天题目略水2333 依旧不粘题目了23333 T1 /*数学题 给定n个斜率 求有多少个三元组 保证两两斜率不同 ans=C(n,3)-ΣC(len[i],2)*(n-len[i])-ΣC(len[ ...

  4. java中的类集框架

    1.什么是类集框架 1.是一组类和接口 2.位于java.util包当中 3.主要用于用户存储和管理对象 4.主要分为三大类——集合.列表和映射 2.类集框架图 虚线框的表示接口,实线框的表示实现类 ...

  5. 共享受限资源,Brian的同步规则

    说明:如果一个变量是boolean,则此变量是原子性的,即赋值和返回值简单的操作在发生时没有中断的可能. 递增不是原子性炒作. 解决共享资源竞争: 1. 通过加锁,锁语句会产生相互排斥的效果,此种机制 ...

  6. Session技术详解

    1.session简介 在WEB开发中,服务器可以为每个用户浏览器创建一个会话对象(session对象),注意:一个浏览器独占一个session对象(默认情况下).因此,在需要保存用户数据时,服务器程 ...

  7. c读写文件相关

    1.打开文件: 函数原型: FILE * fopen(const char * path,const char * mode); 返回值: 文件顺利打开后,指向该流的文件指针就会被返回.如果文件打开失 ...

  8. javascript——处理(获取)浏览器版本、操作系统

    javascript——处理(获取)浏览器版本.操作系统 /** * Created by Administrator on 15-1-12. */ function BroswerUtil() { ...

  9. 2 - Annotations标注

    下面是TestNG标注和参数的一个快速预览 @BeforeSuite 被标注的方法会在这个套件的所有测试执行之前执行  @AfterSuite 被标注的方法会在这个套件的所有测试执行之后执行 @Bef ...

  10. angularjs 实现排序功能

    实现公式:{{orderBy_expression | orderBy:expression:reverse}} Example <script> var app=angular.modu ...