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\) ...
随机推荐
- ConsoleLoggerExtensions.AddConsole(ILoggerFactory)已过时代码修复
0x00.问题 netcoreapp2.2环境下, Startup.cs 代码配置如下 public void Configure(IApplicationBuilder app, IHostingE ...
- springboot activiti 工作流版本 集成代码生成器 shiro 安全框架
官网:www.fhadmin.org 工作流模块---------------------------------------------------------------------------- ...
- python取字母以及数字随机数
一.这里用到了:String模块ascii_letters和digits ''.join(random.sample(string.ascii_letters + string.digits, 9)) ...
- angular异步获取数据后在ngOnInit中无法获取,显示undefined解决办法
两种方法 1 通过*ngif动态加载要数据渲染的dom 2 通过路由导航resolve 第一种感觉太麻烦了,要是一个页面请求多个接口,那就不得不写多个*ngif,本人还是更倾向与第二种发法 具体步骤: ...
- apk反编译工具包for Mac OS的使用
在本文中我将介绍如何在Mac OS X上使用apktool.jar.dex2jar.jd-gui来进行apk的反编译和查看源码.下面会提供每个工具的下载地址. 测试环境:OS X EI Capitan ...
- buffer和cache区别?
写入数据到内存里,这个数据的内存空间称为缓冲区(buffer) 从内存读取数据,这个存储数据的内存空间称为缓存区(cache) 由于大部分网站以读取为主,写入为辅,所以并发写入一般不是问题.
- 使用终端批量下载 B 站视频
需要使用一个叫做 you-get 的命令行程序 可以通过 Homebrew 安装(macOS), 安装命令为 brew install you-get, 其他平台的安装可参考 Github 主页: s ...
- Kubernetes 1.15部署日记-使用kubeadm--<5-6>
5.配置pod网络 5.1下载calico 网络配置文件 [root@k8s-1 libj]# curl -O https://docs.projectcalico.org/v3.6/getting- ...
- c# 日期和时间System.DateTime
- Flink源码阅读(二)——checkpoint源码分析
前言 在Flink原理——容错机制一文中,已对checkpoint的机制有了较为基础的介绍,本文着重从源码方面去分析checkpoint的过程.当然本文只是分析做checkpoint的调度过程,只是尽 ...