题意翻译

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",&ltt);
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(单点修改,区间最大子段和)的更多相关文章

  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. SP1716 GSS3 - Can you answer these queries III 线段树

    问题描述 [LG-SP1716](https://www.luogu.org/problem/SP1716] 题解 GSS 系列的第三题,在第一题的基础上带单点修改. 第一题题解传送门 在第一题的基础 ...

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

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

  4. SP1716 GSS3 - Can you answer these queries III

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

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

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

  7. 【SP1716】GSS3 - Can you answer these queries III(动态DP)

    题目链接 之前用线段树写了一遍,现在用\(ddp\)再写一遍. #include <cstdio> #define lc (now << 1) #define rc (now ...

  8. 题解 SP1716 【GSS3 - Can you answer these queries III】

    \[ Preface \] 没有 Preface. \[ Description \] 维护一个长度为 \(n\) 的数列 \(A\) ,需要支持以下操作: 0 x y 将 \(A_x\) 改为 \( ...

  9. 题解【SP1716】GSS3 - Can you answer these queries III

    题目描述 You are given a sequence \(A\) of \(N (N <= 50000)\) integers between \(-10000\) and \(10000 ...

随机推荐

  1. 软件项目技术点(2)——Canvas之坐标系转换

    AxeSlide软件项目梳理   canvas绘图系列知识点整理 默认坐标系与当前坐标系 canvas中的坐标是从左上角开始的,x轴沿着水平方向(按像素)向右延伸,y轴沿垂直方向向下延伸.左上角坐标为 ...

  2. SQL Server日期格式化

    0   或   100   (*)     默认值   mon   dd   yyyy   hh:miAM(或   PM)       1   101   美国   mm/dd/yyyy       ...

  3. Personal Geodatabase - Can't Create New or Open Existing

    来自:http://forums.arcgis.com/threads/32110-Personal-Geodatabase-Can-t-Create-New-or-Open-Existing Per ...

  4. SharePoint - JavaScript Variable & Functions

    1. MSOWebPartPageFormName 获取当前form的名称,然后可用document.forms[MSOWebPartPageFormName]来得到当前form: 2. _spPag ...

  5. CentOS安装chrome-浏览器

    首先,在CentOS中安装软件,通过yum命令来安装软件,就要在系统中的软件源中添加软件源节点,即在目录./etc/yum.repos.d/下的CentOS-Base.repo文件中做修改:在控制台C ...

  6. 微软开源 PowerShell 并支持 Linux 和 OS X

    微软近日宣布开源 PowerShell,开始支持 Linux 和 OSX.PowerShell 是面向 Windows 和 Windows Server 的自动化平台和可扩展脚本语言,可帮助用户简化系 ...

  7. Oracle分析函数列表分享

    SUM        :该函数计算组中表达式的累积和 MIN        :在一个组中的数据窗口中查找表达式的最小值 MAX        :在一个组中的数据窗口中查找表达式的最大值 AVG     ...

  8. 【Leetcode】【Easy】Climbing Stairs

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  9. (一)selenium发展史(专治selenium小白)

    Jason Huggins在2004年发起了Selenium项目,当时身处ThoughtWorks的他,为了不想让自己的时间浪费在无聊的重复性工作中,幸运的是,所有被测试的浏览器都支持Javascri ...

  10. cropperjs的高度过大(container height too much)

    cropperjs的高度过大(container height too much) 标签(空格分隔): JavaScript 业务需要web头像裁切,用canvas写了个demo卡成一匹马,于是就去寻 ...