线段树操作。

维护一个区间最大连续子段和,左最大连续子段和,右最大连续子段和即可。

最后不知道怎么搞,query的时候返回了个结构体。

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N=50005;
int n,q,a[N],opt,x,y;
struct Segtree{int l,r,lmx,rmx,mx,sum;}t[N<<3];
void pushup(int cur){
t[cur].sum=t[cur<<1].sum+t[cur<<1|1].sum;
t[cur].lmx=max(t[cur<<1].sum+t[cur<<1|1].lmx,t[cur<<1].lmx);
t[cur].rmx=max(t[cur<<1|1].sum+t[cur<<1].rmx,t[cur<<1|1].rmx);
t[cur].mx=max(t[cur<<1].mx,max(t[cur<<1|1].mx,t[cur<<1].rmx+t[cur<<1|1].lmx));
}
void build(int cur,int l,int r){
t[cur].l=l,t[cur].r=r;
if(l==r) {t[cur].sum=t[cur].rmx=t[cur].lmx=t[cur].mx=a[l];return;}
int mid=l+r>>1;
build(cur<<1,l,mid);
build(cur<<1|1,mid+1,r);
pushup(cur);
}
void update(int cur,int c,int now) {
if(t[cur].l==t[cur].r) {t[cur].sum=t[cur].lmx=t[cur].rmx=t[cur].mx=c;return;}
int mid=t[cur].l+t[cur].r>>1;
if(now<=mid) update(cur<<1,c,now);
else update(cur<<1|1,c,now);
pushup(cur);
}
Segtree query(int l,int r,int cur) {
if(l<=t[cur].l&&t[cur].r<=r) return t[cur];
int mid=t[cur].l+t[cur].r>>1;
if(l>mid) return query(l,r,cur<<1|1);
if(r<=mid) return query(l,r,cur<<1);
Segtree x=query(l,r,cur<<1),y=query(l,r,cur<<1|1),ans;
ans.mx=max(x.mx,max(y.mx,x.rmx+y.lmx));
ans.lmx=max(x.lmx,x.sum+y.lmx);
ans.rmx=max(x.rmx+y.sum,y.rmx);
return ans;
}
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
scanf("%d",&q);
build(1,1,n);
while(q--) {
scanf("%d%d%d",&opt,&x,&y);
if(opt) printf("%d\n",query(x,y,1).mx);
else update(1,y,x);
}
return 0;
}

[SPOJ1716] GSS3 - 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. 数据结构(线段树):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 ...

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

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

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

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

  6. SPOJ GSS3 Can you answer these queries III

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

  7. spoj 1557 GSS3 - Can you answer these queries III 线段树

    题目链接 给出n个数, 2种操作, 一种是将第x个数改为y, 第二种是询问区间[x,y]内的最大连续子区间. 开4个数组, 一个是区间和, 一个是区间最大值, 一个是后缀的最大值, 一个是前缀的最大值 ...

  8. SP1716 GSS3 - Can you answer these queries III

    题面 题解 相信大家写过的传统做法像这样:(这段代码蒯自Karry5307的题解) struct SegmentTree{ ll l,r,prefix,suffix,sum,maxn; }; //.. ...

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

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

随机推荐

  1. 洛谷——P1910 L国的战斗之间谍

    https://www.luogu.org/problem/show?pid=1910#sub 题目背景 L国即将与I国发动战争!! 题目描述 俗话说的好:“知己知彼,百战不殆”.L国的指挥官想派出间 ...

  2. SQL Server中如何设置对列的权限

    一.方式一:使用视图 将需要限制用户只能看到特定的几个列.设置成一个视图,然后对这个视图进行权限控制 二.方式二:使用GRANT语句 1.授予相关列的查询权限(SELECT) 在数据库db1中,登录名 ...

  3. Android学习笔记(17):文本框TextView类

    TextView继承自View.用于显示文本.它有很多的子类,掌握其属性是非常重要的. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5 ...

  4. 【cl】解决Fail to create the java Virtual Machine

    eclipse打开,提示Fail to create the java Virtual Machine 解决方法: 1.到eclipse安装目录下,找到eclipse.ini 2.按键盘ctrl+F, ...

  5. 单点登录 SSO 的实现原理 SESSION COOKIE Memcache

    单点登录SSO(Single Sign On)说得简单点就是在一个多系统共存的环境下,用户在一处登录后,就不用在其他系统中登录,也就是用户的一次登录能得到其他所有系统的信任.单点登录在大型网站里使用得 ...

  6. Java 异步转同步 ListenableFuture in Guava

    ListenableFuture的说明 并发编程是一个难题,但是一个强大而简单的抽象可以显著的简化并发的编写.出于这样的考虑,Guava 定义了 ListenableFuture接口并继承了JDK c ...

  7. 【HAOI 2008】 移动玩具

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1054 [算法] 广度优先搜索 [代码] #include<bits/stdc+ ...

  8. TF-IDF算法--关键词句和文本集中每篇文章相关度计算

    关键词句和文本集每篇文章相关度计算:假设语料库中有几万篇文章,每篇文章的长度不一,你任意输入关键词或句子,通过代码以tf-idf值为准检索出来相似度高的文章. 1.TF-IDF概述 TF-IDF是一种 ...

  9. FTP协议讲解

    FTP 概述 文件传输协议(FTP)作为网络共享文件的传输协议,在网络应用软件中具有广泛的应用.FTP的目标是提高文件的共享性和可靠高效地传送数据. 在传输文件时,FTP 客户端程序先与服务器建立连接 ...

  10. 开发vue插件并发布到npm包管理工具的流程

    1-10是开发流程,后面的是发布流程 1. 在Git里面…新建项目   2. 克隆项目到本地用来开发 git clone https://github.com/***/vue-prevent-brow ...