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 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 }.
输入输出格式
输入格式:
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 }.
输出格式:
For each query, print an integer as the problem required.
思路:
这道题与GSS1很像(没做过GSS1的点这里)
但这个题怎么办呢?
大家应该记得,我做GSS1时,并没有建树这个步骤
而是直接将原始节点都变为-inf,然后通过单点修改的方式建树
那么GSS3就很简单了
我们不需要动修改函数(因为都是单点)
直接在循环中引用即可(我才不会告诉你我是先写的GSS3)
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rii register int i
#define rij register int j
#define inf 1073741824
#define rs 65536
using namespace std;
struct nod{
int lm,rm,maxn,sum;
}x[];
int n,q,cz,x1,y1;
void add(int wz,int l,int r,int val,int bh)
{
if(l==r&&l==wz)
{
x[bh].maxn=val;
x[bh].lm=val;
x[bh].rm=val;
x[bh].sum=val;
return;
}
int ltt=(l+r)/;
if(wz<=ltt)
{
add(wz,l,ltt,val,bh*);
}
else
{
add(wz,ltt+,r,val,bh*+);
}
x[bh].sum=x[bh*].sum+x[bh*+].sum;
x[bh].lm=max(x[bh*].lm,x[bh*].sum+x[bh*+].lm);
x[bh].rm=max(x[bh*+].rm,x[bh*+].sum+x[bh*].rm);
x[bh].maxn=max(x[bh*].maxn,max(x[bh*+].maxn,x[bh*].rm+x[bh*+].lm));
}
nod query(int l,int r,int nl,int nr,int bh)
{
nod an,bn;
if(l<nl)
{
l=nl;
}
if(r>nr)
{
r=nr;
}
if(nl==l&&nr==r)
{
an=x[bh];
return an;
}
int ltt=(nl+nr)/;
if(l<=ltt&&r<=ltt)
{
return an=query(l,r,nl,ltt,bh*);
}
if(r>ltt&&l>ltt)
{
return bn=query(l,r,ltt+,nr,bh*+);
}
else
{
an=query(l,r,nl,ltt,bh*);
bn=query(l,r,ltt+,nr,bh*+);
an.maxn=max(an.maxn,max(bn.maxn,an.rm+bn.lm));
an.lm=max(an.lm,an.sum+bn.lm);
an.rm=max(bn.rm,bn.sum+an.rm);
an.sum=an.sum+bn.sum;
return an;
} }
int main()
{
// freopen("brs.in","r",stdin);
// freopen("brs.out","w",stdout);
for(rii=;i<=;i++)
{
x[i].lm=-inf;
x[i].rm=-inf;
x[i].maxn=-inf;
}
scanf("%d",&n);
for(rii=;i<=n;i++)
{
int ltt;
scanf("%d",<t);
add(i,,rs,ltt,);
}
scanf("%d",&q);
for(rii=;i<=q;i++)
{
scanf("%d%d%d",&cz,&x1,&y1);
if(cz==)
{
nod ans=query(x1,y1,,rs,);
printf("%d\n",ans.maxn);
}
else
{
add(x1,,rs,y1,);
}
}
}
SP1716 GSS3 - Can you answer these queries III(单点修改,区间最大子段和)的更多相关文章
- 线段树 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] ...
- SP1716 GSS3 - Can you answer these queries III 线段树
问题描述 [LG-SP1716](https://www.luogu.org/problem/SP1716] 题解 GSS 系列的第三题,在第一题的基础上带单点修改. 第一题题解传送门 在第一题的基础 ...
- SP1716 GSS3 - Can you answer these queries III - 动态dp,线段树
GSS3 Description 动态维护最大子段和,支持单点修改. Solution 设 \(f[i]\) 表示以 \(i\) 为结尾的最大子段和, \(g[i]\) 表示 \(1 \sim i\) ...
- SP1716 GSS3 - Can you answer these queries III
题面 题解 相信大家写过的传统做法像这样:(这段代码蒯自Karry5307的题解) struct SegmentTree{ ll l,r,prefix,suffix,sum,maxn; }; //.. ...
- 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 ...
- 数据结构(线段树):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 ...
- 【SP1716】GSS3 - Can you answer these queries III(动态DP)
题目链接 之前用线段树写了一遍,现在用\(ddp\)再写一遍. #include <cstdio> #define lc (now << 1) #define rc (now ...
- 题解 SP1716 【GSS3 - Can you answer these queries III】
\[ Preface \] 没有 Preface. \[ Description \] 维护一个长度为 \(n\) 的数列 \(A\) ,需要支持以下操作: 0 x y 将 \(A_x\) 改为 \( ...
- 题解【SP1716】GSS3 - Can you answer these queries III
题目描述 You are given a sequence \(A\) of \(N (N <= 50000)\) integers between \(-10000\) and \(10000 ...
随机推荐
- (五)html部分标签元素补充
html标签元素十分的多,一次性掌握全部,那是不可能的,在后续的学习中,会不断补充标签元素... 1.行元素和块元素 行标签元素即是标签元素根据内容大小进行自适应,而不是占据一整行. 如<spa ...
- Hadoop-HA(高可用)集群搭建
Hadoop-HA集群搭建 一.基础准备工作 1.准备好5台Linux系统虚拟服务器或物理服务器 我这里演示采用虚拟服务器搭建Hadoop-HA集群,各自功能分配如下: NameNode节点:vt-s ...
- Resharper 的快捷键
编辑 Ctrl + Space 代码完成 Ctrl + Shift + Space代码完成 Ctrl + Alt + Space代码完成 Ctrl + P 显示参数信息 Alt + Inser ...
- 编程语言的发展历史剧。(参考https://baijiahao.baidu.com/s?id=1588675986991787716&wfr=spider&for=pc)
1800年 约瑟夫·玛丽·雅卡尔(Joseph Marie Jacquard),设计出人类历史 上首台可设计织布机——雅卡尔织布机,对将来发展出其他可编程机器起了重要作用 1842年 阿达·洛夫莱斯( ...
- 使用Anaconda管理环境
Anaconda指的是一个开源的python发行版本,其包含了conda.Python等180多个科学包及其依赖项. Anaconda是一个开源的包.环境管理器,可以用于在同一个机器上安装不同版本的软 ...
- python函数名称空间与作用域、闭包
一.命名空间概念 1.命名空间(name space) 名称空间是存放名字的地方. 若变量x=1,1存放在内存中,命名空间是存放名字x.x与1绑定关系的地方. 2.名称空间加载顺序 python te ...
- Stage2--Python的数据类型
说在前面: Stage1-Stage4简单介绍一下Python语法,Stage5开始用python实现一些实际应用,语法的东西到处可以查看到,学习一门程序语言的最终目的是应用,而不是学习语法,语法本事 ...
- Kafka监控利器
开发过程中,kafka几乎是标配的Mq,如果有一个kafka的监控助手,哪就更完美了,常用的kafka监控工具有 KafkaOffsetMonitor .Kafka Manager.Capillary ...
- Siebel应用数据结构层次
在Siebel应用里数据在多个层次上使用了不同的定义方式,每一个层次侧重于数据的不同的特征,主要分为数据用户界面层定义(UI),业务逻辑层定义(Business Layer,可以是业务含义层)以及数据 ...
- Flask入门模板过滤器与测试器(五)
1 模板引擎之过滤器 概念 : 过滤器本质上是个转换函数,第一个参数是待过滤的变量.如果它有第二个参数,模板中就必须传进去. 过滤器使用管道符| 放在{{ }} Jinja2模板引擎提供了丰富的内置过 ...