//在gss1的基础上加了修改操作,一样的做法,加一个modify函数就可以了
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int N=5e4+; int n,m,type,l,r;
int L,R,M,S;
struct Tree
{
int l,r,mid;
int sum,lmaxn,rmaxn,maxn;
}tree[N<<]; int read()
{
char c=getchar();int num=,f=;
for(;!isdigit(c);c=getchar())
if(c=='-')
f=-;
for(;isdigit(c);c=getchar())
num=num*+c-'';
return num*f;
} void pushup(int root)
{
tree[root].maxn=max(tree[root<<].maxn,max(tree[root<<|].maxn,tree[root<<].rmaxn+tree[root<<|].lmaxn));
tree[root].lmaxn=max(tree[root<<].lmaxn,tree[root<<].sum+tree[root<<|].lmaxn);
tree[root].rmaxn=max(tree[root<<|].rmaxn,tree[root<<|].sum+tree[root<<].rmaxn);
tree[root].sum=tree[root<<].sum+tree[root<<|].sum;
} void build(int root,int l,int r)
{
tree[root].l=l,tree[root].r=r,tree[root].mid=l+r>>;
if(l==r)
{
tree[root].sum=tree[root].maxn=tree[root].rmaxn=tree[root].lmaxn=read();
return;
}
build(root<<,l,tree[root].mid);
build(root<<|,tree[root].mid+,r);
pushup(root);
} void Modify(int root,int pos,int x)
{
if(tree[root].l==tree[root].r&&tree[root].l==pos)
{
tree[root].lmaxn=tree[root].rmaxn=tree[root].maxn=tree[root].sum=x;
return;
}
if(pos<=tree[root].mid)
Modify(root<<,pos,x);
else
Modify(root<<|,pos,x);
pushup(root);
} void Qeuery(int root,int l,int r,int &L,int &R,int &M,int &S)
{
if(l<=tree[root].l&&tree[root].r<=r)
{
L=tree[root].lmaxn,
R=tree[root].rmaxn,
M=tree[root].maxn,
S=tree[root].sum;
return;
}
if(tree[root].mid>=r)
{
Qeuery(root<<,l,r,L,R,M,S);
}
else if(tree[root].mid<l)
{
Qeuery(root<<|,l,r,L,R,M,S);
}
else
{
int lL=,lR=,lM=,lS=,rL=,rR=,rM=,rS=;
Qeuery(root<<,l,tree[root].mid,lL,lR,lM,lS);
Qeuery(root<<|,tree[root].mid+,r,rL,rR,rM,rS);
L=max(lL,lS+rL);
R=max(rR,rS+lR);
M=max(lR+rL,max(lM,rM));
S=lS+rS;
}
} int main()
{
n=read();
build(,,n);
m=read();
for(int i=;i<=m;++i)
{
type=read();
l=read(),r=read();
if(!type)
Modify(,l,r);
else
{
Qeuery(,l,r,L,R,M,S);
printf("%d\n",M);
}
}
return ;
}

GSS3 C - Can you answer these queries III的更多相关文章

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

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

  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. GSS3 SPOJ 1716. Can you answer these queries III gss1的变形

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

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

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

  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. SP1716 GSS3 - Can you answer these queries III(单点修改,区间最大子段和)

    题意翻译 nnn 个数, qqq 次操作 操作0 x y把 AxA_xAx​ 修改为 yyy 操作1 l r询问区间 [l,r][l, r][l,r] 的最大子段和 题目描述 You are give ...

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

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

随机推荐

  1. jwt 0.9.0(一)推荐jwt理由

    本人一直有良好的写技术博文的习惯,最近研究 jwt 有点点心得,赶紧记下来. 我推荐使用jwt(Json Web Token)这种客户端存储状态方式,代替传统的服务端存储状态方式(比如redis存储s ...

  2. kafka和zookeeper安装部署(版本弄不好就是坑)

    yum install -y unzip zip 配置host vi /etc/host172.19.68.10 zk1 1. zookeeper zookeeper下载地址 http://mirro ...

  3. Codechef TSUM2 Sum on Tree 点分治、李超线段树

    传送门 点分治模板题都不会迟早要完 发现这道题需要统计所有路径的信息,考虑点分治统计路径信息. 点分治之后,因为路径是有向的,所以对于每一条路径都有向上和向下的两种.那么如果一条向上的路径,点数为\( ...

  4. IdentityServer4实现OAuth2.0四种模式之客户端模式

    一,准备内容 IdentityServer4 是Asp.net core的一个中间件,用于添加符合OpenId Connect和OAuth2.0规范的终端到Asp.net Core应用.在这里简单介绍 ...

  5. windows下安装hexo和生成博客

    首先在电脑上安装node和git,这个只要在相关官网的下载然后一步安装即可. 然后在你的电脑上新建一个文件夹,用来存放你的博客文件,比如创建hexo 进入该文件,右键打开git bash 安装hexo ...

  6. MySQL连接使用

    在mysql查询中,我们会通过排序,分组等在一张表中读取数据,这是比较简单的,但是在真正的应用中经常需要从多个数据表中读取数据.下面就为大家介绍这种方式,链接查询join. INNER JOIN(内连 ...

  7. TR-业务流程图

    今天看到一篇关于票据业务的培训文档,介绍比较全面,分享下: https://wenku.baidu.com/view/f3dd3ee988eb172ded630b1c59eef8c75ebf9577. ...

  8. 【雅思】【绿宝书错词本】List37~48

    List 37 ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ List 38 ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ List 39 ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ...

  9. linux各种服务的搭建

    https://blog.csdn.net/qq_33571718/article/details/81543408    VPN --linux服务搭建 https://blog.csdn.net/ ...

  10. 腿部——哑铃&杠铃