传送门 gss1 gss3

spoj gss系列=最大字段和套餐

gss1就是gss3的无单点修改版

有区间查询和单点修改,考虑用线段树维护

我们要维护区间权值和\(s\),区间最大前缀和\(xl\)和最大后缀和\(xr\),以及最大子段和\(x\)

在pushup的时候,这样维护 代码里有

\[a[o].s=a[lc].s+a[rc].s$$$$a[o].xl=max(a[lc].xl,a[lc].s+a[rc].xl)$$$$a[o].xr=max(a[rc].xr,a[lc].xr+a[rc].s)$$$$a[o].x=max(max(a[lc].x,a[rc].x),a[lc].xr+a[rc].xl)
\]

其实是懒得写文字

// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define LL long long
#define il inline
#define re register
#define db double
#define lc (o<<1)
#define rc ((o<<1)|1)
#define mid ((l+r)>>1)
#define max(a,b) ((a)>(b)?(a):(b)) using namespace std;
const int N=50000+10,inf=999999999;
il LL rd()
{
re LL x=0,w=1;re char ch=0;
while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*w;
}
struct sgmt
{
LL s,xl,xr,x;
}a[N<<2];
il void psup(int o)
{
a[o].s=a[lc].s+a[rc].s;
a[o].xl=max(a[lc].xl,a[lc].s+a[rc].xl);
a[o].xr=max(a[rc].xr,a[lc].xr+a[rc].s);
a[o].x=max(max(a[lc].x,a[rc].x),a[lc].xr+a[rc].xl);
}
il void bui(int o,int l,int r)
{
if(l==r) {a[o].s=a[o].xl=a[o].xr=a[o].x=rd();return;}
bui(lc,l,mid),bui(rc,mid+1,r);
psup(o);
}
il void modi(int o,int l,int r,int x,int y)
{
if(l==r) {a[o].s=a[o].xl=a[o].xr=a[o].x=y;return;}
if(x<=mid) modi(lc,l,mid,x,y);
else modi(rc,mid+1,r,x,y);
psup(o);
}
il sgmt quer(int o,int l,int r,int ll,int rr)
{
if(ll<=l&&r<=rr) return a[o];
if(rr<=mid) return quer(lc,l,mid,ll,rr);
else if(ll>mid) return quer(rc,mid+1,r,ll,rr);
else
{
sgmt an,aa,bb;
aa=quer(lc,l,mid,ll,mid),bb=quer(rc,mid+1,r,mid+1,rr);
an.s=aa.s+bb.s;
an.xl=max(aa.xl,aa.s+bb.xl);
an.xr=max(bb.xr,aa.xr+bb.s);
an.x=max(max(aa.x,bb.x),aa.xr+bb.xl);
return an;
}
}
int n,m; int main()
{
n=rd();
bui(1,1,n);
m=rd();
while(m--)
{
int op=rd(),x=rd(),y=rd();
if(op==0) modi(1,1,n,x,y);
else printf("%lld\n",quer(1,1,n,x,y).x);
}
return 0;
}

spoj gss1 gss3的更多相关文章

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

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

  2. SPOJ - GSS1&&GSS3

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

  3. SPOJ GSS1 & GSS3&挂了的GSS5

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

  4. 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]| ≤ ...

  5. [题解] SPOJ GSS1 - Can you answer these queries I

    [题解] SPOJ GSS1 - Can you answer these queries I · 题目大意 要求维护一段长度为 \(n\) 的静态序列的区间最大子段和. 有 \(m\) 次询问,每次 ...

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

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

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

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

  8. SPOJ GSS1 Can you answer these queries I[线段树]

    Description You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A q ...

  9. SPOJ GSS1 Can you answer these queries I

    Time Limit: 115MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Description You are g ...

随机推荐

  1. Java ThreadLocal 理解

    ThreadLocal 概念: ThreadLocal不是用来解决对象共享访问的问题,而主要是提供了保存对象的方法和避免参数传递的方便的对象访问方式. ThreadLocal并不是一个Thread,而 ...

  2. Luogu3297 SDOI2013逃考(半平面交+最短路)

    把每个人的监视范围看成点,相邻的两个监视范围连边,那么跑一遍最短路就可以了(事实上边权都为1可以直接bfs).显然存在最优路线没有某个时刻同时被多于两人监视,要到达另一个区域的话完全可以经过分界线而不 ...

  3. (转)二分图匹配匈牙利算法与KM算法

    匈牙利算法转自于: https://blog.csdn.net/dark_scope/article/details/8880547 匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名 ...

  4. virtualenv 模块

    作用 安装虚拟环境 下载组件 pip3 install virtualenv 使用 命令行创建使用 """ 创建虚拟环境 """ virtu ...

  5. pandas的筛选功能,跟excel的筛选功能类似,但是功能更强大。

    Select rows from a DataFrame based on values in a column -pandas 筛选 https://stackoverflow.com/questi ...

  6. [JOI2017] サッカー (Soccer)

    原题题面看不懂的可以看下面的\(CJ\)版中文题面 $ $ \(CJ\)版: $ $ 这道题是\(JOI\)的\(T4\),放到联赛大概就是\(Day2,T3\)的难度 $ $ \(5\)分: 这一档 ...

  7. 【转】Context Switches上下文切换性能详解

    http://blog.csdn.net/aiai5251/article/details/50015745 Context Switches 上下文切换,有时也被称为进程切换(process swi ...

  8. POSIX 线程取消点的 Linux 实现

    http://blog.csdn.net/stevenliyong/article/details/4364039 原文链接:http://blog.solrex.cn/articles/linux- ...

  9. Ubuntu中让归档管理器支持rar和7z格式

    由于版权等原因,Linux系统不能直接支持rar和7z,需要手动安装第三方工具. rar支持 sudo apt install unrar 7z支持 sudo apt install p7zip-fu ...

  10. CF520E Pluses everywhere

    题目大意 给定一个 n 位的十进制数,可以在数字之间加 k 个' + ',得到一个式子,求每种方案的这个式子的和 分析: 容易想到将式子的和转化为每个数字的贡献值之和. 设数组a为:a(n-1),a( ...