传送门

(分析见正睿2018.10.1笔记)

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
struct node {
int pre,sur,ans,sum;
};
node d[];
inline node work(node x,node y){
node res;
res.sum=x.sum+y.sum;
res.pre=max(x.pre,x.sum+y.pre);
res.sur=max(y.sur,y.sum+x.sur);
res.ans=max(max(x.ans,y.ans),x.sur+y.pre);
return res;
}
inline void update(int le,int ri,int wh,int pl,int k){
if(le==ri){
d[wh].pre=d[wh].sur=d[wh].ans=d[wh].sum=k; return;
}
int mid=(le+ri)>>;
if(mid>=pl)update(le,mid,wh<<,pl,k);
else update(mid+,ri,wh<<|,pl,k);
d[wh]=work(d[wh<<],d[wh<<|]);
return;
}
inline node q(int le,int ri,int wh,int x,int y){
if(le>=x&&ri<=y){
return d[wh];
}
int mid=(le+ri)>>,cnt=;
node a,b;
if(mid>=x)cnt+=,a=q(le,mid,wh<<,x,y);
if(mid<y)cnt+=,b=q(mid+,ri,wh<<|,x,y);
if(cnt==)return a;
if(cnt==)return b;
return work(a,b);
}
int main(){
int n,m,i,j,k,x,y;
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d",&x);
update(,n,,i,x);
}
scanf("%d",&m);
for(i=;i<=m;i++){
scanf("%d%d%d",&k,&x,&y);
if(k==){
update(,n,,x,y);
}else {
printf("%d\n",q(,n,,x,y).ans);
}
}
return ;
}

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

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

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

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

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

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

  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. [SPOJ1716] GSS3 - Can you answer these queries III

    线段树操作. 维护一个区间最大连续子段和,左最大连续子段和,右最大连续子段和即可. 最后不知道怎么搞,query的时候返回了个结构体. #include <cstdio> #include ...

  9. SPOJ GSS3 Can you answer these queries III

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

随机推荐

  1. (转)libcurl库使用方法,好长,好详细。

    一.ibcurl作为是一个多协议的便于客户端使用的URL传输库,基于C语言,提供C语言的API接口,支持DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP ...

  2. CI框架后台添加左侧导航栏出现的一系列问题

  3. bzoj 5403 Marshland

    $n \leq 50$ sol: 放一个在 $x$ 处拐弯的 $L$ 形石头相当于在水平和垂直方向上各选一个与 $x$ 相邻的点,全局不能重复选 最小化危险度,相当于满足这些限制的情况下石头盖住的点危 ...

  4. 【LeetCode】075. Sort Colors

    Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...

  5. 异步通信rabbitmq——消息重试

    目标: 利用RabbitMQ实现消息重试和失败处理,实现可靠的消费消费.在消息消费异常时,自动延时将消息重试,当重试超过一定次数后,则列为异常消息,等待后续特殊处理. 准备: TTL:Time-To- ...

  6. 基于JQ的多选/全选/反选及获取选中的值

    <!-- author:青芒 --> <!DOCTYPE html> <html lang="en"> <head> <met ...

  7. 学习动态性能表(16)--v$rowcache

    学习动态性能表 第16篇--V$ROWCACHE  2007.6.12 本视图显示数据字典缓存(也叫rowcache)的各项统计.每一条记录包含不同类型的数据字典缓存数据统计,注意数据字典缓存有层次差 ...

  8. 基于dubbo的SOA项目改造

    工程改造: 1.原来工程删除掉表现层的模块,将表现层独立出来. 2.将原来的工程改造.将service的打包方式改为改为war. 3.在service模块中添加web.xml文件 4.在web.xml ...

  9. CentOS7安装wget 及配置

    yum -y install wget yum -y install setup yum -y install perl

  10. MyBatis的高级映射之多对一

    使用传统方式的形式 使用MyBatis的方式 这样会产生两条语句 使用ResultMap的方式,对结果进行映射和转换,自己控制 两条语句变成一条语句,然后进行映射,这时Student类中包含一个 Cl ...