于是我拿合并返回节点的线段树(我也不知道应该叫什么名)水了一下$GSS1$

比$NOIp$之前写的不知道高到哪里去了,并且只用了$\frac{1}{3}$的时间

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define lc x<<1
#define rc x<<1|1
#define mid ((l+r)>>1)
#define lson x<<1,l,mid
#define rson x<<1|1,mid+1,r
using namespace std;
typedef long long ll;
const int N=5e5+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n,Q,a,b;
struct Node{
int sum,mx,lm,rm;
Node():sum(),mx(),lm(),rm(){}
}t[N<<];
Node Merge(Node a,Node b){
Node re;
re.sum=a.sum+b.sum;
re.mx=max(a.rm+b.lm,max(a.mx,b.mx));
re.lm=max(a.lm,a.sum+b.lm);
re.rm=max(b.rm,b.sum+a.rm);
return re;
}
void merge(int x){
t[x].sum=t[lc].sum+t[rc].sum;
t[x].mx=max(t[lc].rm+t[rc].lm,max(t[lc].mx,t[rc].mx));
t[x].lm=max(t[lc].lm,t[lc].sum+t[rc].lm);
t[x].rm=max(t[rc].rm,t[rc].sum+t[lc].rm);
}
void build(int x,int l,int r){
if(l==r) t[x].sum=t[x].mx=t[x].lm=t[x].rm=read();
else{
build(lson);
build(rson);
merge(x);
}
}
Node segQue(int x,int l,int r,int ql,int qr){
if(ql<=l&&r<=qr) return t[x];
else{
if(qr<=mid) return segQue(lson,ql,qr);
if(mid<ql) return segQue(rson,ql,qr);
return Merge(segQue(lson,ql,qr),segQue(rson,ql,qr));
}
}
int main(){
freopen("in","r",stdin);
n=read();
build(,,n);
Q=read();
for(int i=;i<=Q;i++) a=read(),b=read(),printf("%d\n",segQue(,,n,a,b).mx);
}

GSS1的更多相关文章

  1. GSS系列(1)——GSS1&&GSS3

    题意:询问一个区间内的最大连续子段和(GSS1),并且有单点修改的操作(GSS2). 思路:这个题目在老人家的大白鼠里出现过,不过那个是求两个下标,并且相同取更小值.——传的东西更多,判断也稍微繁琐一 ...

  2. GSS3 SPOJ 1716. Can you answer these queries III gss1的变形

    gss2调了一下午,至今还在wa... 我的做法是:对于询问按右区间排序,利用splay记录最右的位置.对于重复出现的,在splay中删掉之前出现的位置所在的节点,然后在splay中插入新的节点.对于 ...

  3. SPOJ GSS1 && GSS3 (无更新/更新单点,并询问区间最大连续和)

    http://www.spoj.com/problems/GSS1/ 题意:无更新询问区间最大连续和. 做法:线段树每个节点维护sum[rt],maxsum[rt],lsum[rt],rsum[rt] ...

  4. spoj gss1 gss3

    传送门 gss1 gss3 spoj gss系列=最大字段和套餐 gss1就是gss3的无单点修改版 有区间查询和单点修改,考虑用线段树维护 我们要维护区间权值和\(s\),区间最大前缀和\(xl\) ...

  5. 线段树 SP1043 GSS1 - Can you answer these queries I

    SP1043 GSS1 - Can you answer these queries I 题目描述 给出了序列A[1],A[2],-,A[N]. (a[i]≤15007,1≤N≤50000).查询定义 ...

  6. SPOJ - GSS1 —— 线段树 (结点信息合并)

    题目链接:https://vjudge.net/problem/SPOJ-GSS1 GSS1 - Can you answer these queries I #tree You are given ...

  7. SPOJ - GSS1&&GSS3

    GSS1 #include<cstdio> #include<iostream> #define lc k<<1 #define rc k<<1|1 u ...

  8. SPOJ GSS1 & GSS3&挂了的GSS5

    线段树然后yy一下,搞一搞. GSS1: 题意:求最大区间和. #include <cstdio> #include <algorithm> using namespace s ...

  9. SPOJ GSS1 - Can you answer these queries I(线段树维护GSS)

    Can you answer these queries I SPOJ - GSS1 You are given a sequence A[1], A[2], -, A[N] . ( |A[i]| ≤ ...

随机推荐

  1. Spark环境搭建(上)——基础环境搭建

    Spark摘说 Spark的环境搭建涉及三个部分,一是linux系统基础环境搭建,二是Hadoop集群安装,三是Spark集群安装.在这里,主要介绍Spark在Centos系统上的准备工作--linu ...

  2. ImportError: No module named 'BaseHTTPServer':解决方案

    利用python写了一小段代码,里面使用到了Python标准库的BaseHTTPServer来构建一个基础HTTP服务器: 1 #-*- coding:utf-8 -*- 2 import http. ...

  3. cesium编程入门(一)cesium简介

    cesium编程入门 cesium是什么 Cesium 是一个跨平台.跨浏览器的展示三维地球和地图的 javascript 库. Cesium 使用WebGL 来进行硬件加速图形,使用时不需要任何插件 ...

  4. Django App(三) View+Template

    接着上一节(二)的内容,首先启动站点,通过界面添加Question和Choice两张表的数据,因为接下来,要向polls app里面添加views. 1.添加数据如下(这里是通过界面操作添加的数据) ...

  5. TypeScript和Node模块解析策略

    一般我们在模块化编码时,总会导入其它模块,通常我们使用如下语法: import { A } from './a'; // ES6语法 import { A } from 'a'; var A = re ...

  6. Java读书推荐

    想要深入掌握一门技术,读书是必不可少的一步,也是最重要的一步.有些书需要读很多遍才能深入理解,经过几本甚至几十本书的熏陶,才能让你在这个行业中越走越远,爱上这个行业,抽出时间多读本书吧,读书会让人如虎 ...

  7. python3的一些改动常用到的

    更多的内容会接下来说明,只举几个例子. https://docs.python.org/2/library/2to3.html 1. map的输出,要在前面加list转化 2. map(lambda ...

  8. 在CMainFrame里使用定时器是有讲究的

    设置定时器函数:SetTimer 单位毫秒 销毁定时器函数:KillTimer 消息:WM_TIMER 注意事项: (1)不要在构造函数里设置定时器. (2)不要在析构函数里销毁定时器. 原因:构造函 ...

  9. Linux常用命令(一)--系统命令

    命令字 命令字 [命令选项] [命令参数] 1. 命令中所有字符区分大小写 2. 命令选项分为短格式(-)及长格式(–) 3. 必须在命令行提示符下输入命令 4. 命令中的各个部分至少需要一个空格分隔 ...

  10. Storm Topology Parallelism

    Understanding the Parallelism of a Storm Topology What makes a running topology: worker processes, e ...