博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SPOJ GSS3 Can you answer these queries III[线段树]
阅读量:7250 次
发布时间:2019-06-29

本文共 1896 字,大约阅读时间需要 6 分钟。

Description

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

Input

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

Output

For each query, print an integer as the problem required.

Example

Input:41 2 3 441 1 30 3 -31 2 41 3 3Output:64-3

GSS1加个单点修改
#include 
#include
#include
#include
#define m ((l+r)>>1)#define lson o<<1,l,m#define rson o<<1|1,m+1,r#define lc o<<1#define rc o<<1|1using namespace std;typedef long long ll;const int N=5e5+5,INF=2e9+5;inline int read(){ char c=getchar();int x=0,f=1; while(c<'0'||c>'9'){
if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f;}int n,q,op,x,y;struct node{ int sum,mx,pre,suf;}t[N<<2];void merge(int o){ t[o].sum=t[lc].sum+t[rc].sum; t[o].mx=max(t[lc].suf+t[rc].pre,max(t[lc].mx,t[rc].mx)); t[o].pre=max(t[lc].pre,t[lc].sum+t[rc].pre); t[o].suf=max(t[rc].suf,t[rc].sum+t[lc].suf);}void build(int o,int l,int r){ if(l==r) t[o].sum=t[o].mx=t[o].pre=t[o].suf=read(); else{ build(lson); build(rson); merge(o); }}int qpre(int o,int l,int r,int ql,int qr){ if(ql<=l&&r<=qr) return t[o].pre; else if(qr<=m) return qpre(lson,ql,qr); else return max(qpre(lson,ql,qr),t[lc].sum+qpre(rson,ql,qr));}int qsuf(int o,int l,int r,int ql,int qr){ if(ql<=l&&r<=qr) return t[o].suf; else if(m

 

 

转载地址:http://zrqbm.baihongyu.com/

你可能感兴趣的文章
负载均衡之基于DNS负载
查看>>
Hadoop集群(第8期)_HDFS初探之旅
查看>>
Centos6.8 64 位 Discuz 运行环境
查看>>
我的友情链接
查看>>
社交系统ThinkSNS+预售活动结束倒计时
查看>>
克隆虚拟机
查看>>
资讯直播,会是下一个新风口吗
查看>>
企业邮箱自建战略优势大盘点
查看>>
关于EIGRP一些小问题的解答
查看>>
ubuntu linuxqq_v1.0.2_i386.tar.gz 安装方法
查看>>
医疗信息化、医学、医院管理、医疗器械资料下载
查看>>
cmake masql 安装
查看>>
JDK-7u4(rpm)+Tomcat-7.0+JavaCenterHome
查看>>
win10系统的一些经验
查看>>
os和shutil模块
查看>>
C/C++编译过程详解
查看>>
31、路由器搭建帧中继云
查看>>
模板分页封装
查看>>
分布式系统之Quorum (NRW)算法
查看>>
jQuery:理解$(document).ready()的特殊写法
查看>>