GSS3 C - Can you answer these queries III

//在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的更多相关文章
- 「 SPOJ GSS3 」 Can you answer these queries III
# 题目大意 GSS3 - Can you answer these queries III 需要你维护一种数据结构,支持两种操作: 单点修改 求一个区间的最大子段和 # 解题思路 一个区间的最大子段 ...
- 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 ...
- GSS3 SPOJ 1716. Can you answer these queries III gss1的变形
gss2调了一下午,至今还在wa... 我的做法是:对于询问按右区间排序,利用splay记录最右的位置.对于重复出现的,在splay中删掉之前出现的位置所在的节点,然后在splay中插入新的节点.对于 ...
- 数据结构(线段树):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
SP1716 GSS3 - Can you answer these queries III 题意翻译 n 个数,q 次操作 操作0 x y把A_xAx 修改为yy 操作1 l r询问区间[l, r] ...
- Can you answer these queries III
Can you answer these queries III 题目:洛谷 SPOJ [题目描述] 给定长度为N的数列A,以及M条指令,每条指令可能是以下两种之一: 1.“0 x y”,把A[x]改 ...
- 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 ...
- 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 ...
- SP1716 GSS3 - Can you answer these queries III - 动态dp,线段树
GSS3 Description 动态维护最大子段和,支持单点修改. Solution 设 \(f[i]\) 表示以 \(i\) 为结尾的最大子段和, \(g[i]\) 表示 \(1 \sim i\) ...
随机推荐
- CF1097G Vladislav and a Great Legend 组合、树形背包
传送门 看到\(k\)次幂求和先用斯特林数拆幂:\(x^k = \sum\limits_{i=1}^k \binom{x}{i}\left\{ \begin{array}{cccc} k \\ i \ ...
- go 学习笔记(3) 基础结构
package main import ( "fmt" ) const NAME string = "imooc" var a string = "慕 ...
- java中反射的使用
结合demo理解反射: import java.lang.reflect.*; /** * 反射使用 **/ public class ReflectDemo{ public static void ...
- java之hibernate之单向的多对多关联映射
这篇 单向的多对多关联映射 1.如何在权限管理中,角色和权限之间的关系就是多对多的关系,表结构为: 2.类结构 Permission.java public class Permission impl ...
- power shell命令添加SharePoint用户组与用户(用户为域用户)
查看SharePoint用户组 Get-PnPGroup 查看某一用户组 Get-PnPGroup -Identity "用户组名" 查看某一用户组下的所有成员 Get-PnPGr ...
- .net 调用存储过程
语言:C# 一.调用带输入参数的存储过程 首先自然是在查询分析器里创建一个存储过程喽~~ 如下所示: create proc proc_1 @uid int, @pwd varchar(255) ...
- vue 关于子组件向父组件传值$emit触发无效问题
先贴上代码 子组件代码 //子组件请求接口,用自己封装的axios getupdate(){ this.$post({ url:this.$apis.unitupdate, postType:'jso ...
- Air for ANE:打包注意的地方
来源:http://blog.csdn.net/hero82748274/article/details/8631982 今天遇到了一个打包ANE 文件的问题,导致花费了几个小时查找,最后师弟的一句话 ...
- js 数组的深度拷贝 的四种实现方法
首先声明本人资质尚浅,本文只用于个人总结.如有错误,欢迎指正.共同提高. --------------------------------------------------------------- ...
- SVN提交错误及使用技巧
错误1: Some of selected resources were not added to version control. Some of selected resources were n ...