于是我拿合并返回节点的线段树(我也不知道应该叫什么名)水了一下$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. jQuery中获取文档的高度、可视区域高度以及滚动条距页面顶部的高度

    在写页面的时候,经常会碰到这样的情况,就是要获取文档的高度.可视区域高度或者滚动条距页面顶部的高度等情况. 但我总是有些爱搞混淆了,这里还是简单做个笔记吧,这里只限于使用jQuery来获取. 1.获取 ...

  2. Java | 原来 try 还可以这样用啊?!

    本文首发于 http://youngzy.com/ 习惯了这样的try: try { } catch (Exception e) { } 看到了这样的try,觉得有点神奇: try(...) { } ...

  3. Thinkphp 3.2中文章详情页的上一篇 下一篇文章功能

      额 简单2句话解释下 获取上一篇文章的原理,其实就是以当前文章的id为起点进行进行查询,例如id=5的文章 select * from article where (article_id<5 ...

  4. 怎么使用linux命令重启服务器

    一下的命令都可以重启Linux服务器: 1.shutdown -r now 2.reboot 3.startx

  5. mysql alter总结

    mysql alter总结(转载) 1:删除列 ALTER TABLE [表名字] DROP [列名称] 2:增加列 ALTER TABLE [表名字] ADD [列名称] INT NOT NULL  ...

  6. Performance Testing 前期准备以及场景设计

    性能测试的session参加过几个,也查阅了很多相关的资料.年前被分配了测试任务,一直拖到现在,准备开始做的时候,才发现真的是不知道如何做起啊.今天和同事聊了一下,有很大启发.测试小白一枚,只分享一下 ...

  7. SQLServer导出数据表结构

    SELECT (case when a.colorder=1 then d.name else '' end)表名, a.colorder 字段序号, a.name 字段名, (case when C ...

  8. linux 磁盘加密和tpm搭配使用1

    一.基本名称,容易混淆 1.dm-crypt是linux的2.6内核开始集成的一种磁盘加密功能.十几年来,连sche调度算法都被改了N次,但dm-crypt一直稳定在内核中,稳定性还是很好的. 2.c ...

  9. Go_Hello word

    与Go相关直接命令有哪些? go get    获取远程包 go run    直接运行程序 go bulid  测试编译 go fmt    格式化代码 go install       编译包文件 ...

  10. junit源码解析--捕获测试结果

    OK,前面的博客我们整理了junit运行完了所有的测试用例,那么OK了,现在开始该收集测试结果了. 在这最后一步中,junit主要是玩一个类,TestResult.这里类中封装了几个参数,在初始化这个 ...