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\) ...
 
随机推荐
- robotFramework_Jquery语法
			
向您的页面添加 jQuery 库 jQuery 库位于一个 JavaScript 文件中,其中包含了所有的 jQuery 函数.那么我们怎么判断页面中是否使用了Jquery库呢? 如下图,当页面中引入 ...
 - 深度自适应增量学习(Incremental Learning Through Deep Adaptation)
			
深度自适应增量学习(Incremental Learning Through Deep Adaptation) 2018-05-25 18:56:00 木呆呆瓶子 阅读数 10564 收藏 更多 分 ...
 - git 学习笔记 ---撤销修改
			
自然,你是不会犯错的.不过现在是凌晨两点,你正在赶一份工作报告,你在readme.txt中添加了一行: $ cat readme.txt Git is a distributed version co ...
 - redis连接相关命令
			
命令名称:echo 语法:echo message 功能: 打印一个特定的信息message,测试时使用. 返回值: message自身 命令名称:ping 语法:ping 功能: 使用客户端向red ...
 - Linux进程间通信—使用共享内存
			
Linux进程间通信-使用共享内存 转自: https://blog.csdn.net/ljianhui/article/details/10253345 下面将讲解进程间通信的另一种方式,使用共享内 ...
 - NEST 增删改查
			
/// <summary> /// HEAD /employee/employee/1 /// </summary> public void DocumentExists() ...
 - MyBatis 中#和$符号的区别
			
#相当于对数据 加上 双引号,$相当于直接显示数据 1. #将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号.如:order by #user_id#,如果传入的值是111,那么解析成sq ...
 - css列表滑动防止被底部遮住和适配屏幕长一点的机型处理
			
1.移动端处理列表滑动的时候,微信底下有自带的返回页面按钮,经常会被遮住,遇到屏幕长一点的,下面会短一大截,以下用此方法可以解决..container{ position:relative; back ...
 - Web 标准构成
			
Web标准不是某一个标准,而是由W3C和其他标准化组织制定的一系列标准的集合.主要包括结构(Structure).表现(Presentation)和行为(Behavior)三个方面. 结构标准:结构用 ...
 - SIM900 HTTP POST
			
AT+SAPBR=3,1,"CONTYPE","GPRS" OK AT+SAPBR=3,1,"APN","CMNET" ...