传送门 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. ansible系列7-mysql_user模块

    添加mysql的用户和权限.密码 新增mysql用户zhang,设置登录密码zhang,给予权限zabbix.*:ALL ansible dba -m mysql_user -a 'login_hos ...

  2. BZOJ4182 Shopping(点分治+树形dp)

    点分治,每次考虑包含根的连通块,做树形多重背包即可,dfs序优化.注意题面给的di范围是假的,坑了我0.5h,心态炸了. #include<iostream> #include<cs ...

  3. 快乐的Lambda表达式(二)

    转载:http://www.cnblogs.com/jesse2013/p/happylambda-part2.html 快乐的Lambda表达式 上一篇 背后的故事之 - 快乐的Lambda表达式( ...

  4. length、length()、size()区别 List与String相互转换

      字符串 数组 List对象 定义 String str = ""; String[] s = new String[5]; char[] s; List<String&g ...

  5. MT【47】求一道分式的最值

    评:技巧性很大,需要敏锐的洞察力通过柯西不等式把分母变成一样.请记住这个变形$$(a+b+ab+1)=(a+1)(b+1)\le\sqrt{(a^2+1)(b^2+1)}$$

  6. 自学Python2.1-基本数据类型-字符串str(object) 上

    自学Python之路 自学Python2.1-基本数据类型-字符串str(object) 上 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串 ...

  7. Android 手势&触摸事件

    在刚开始学Android的时候,就觉得Google的文档不咋样,在研究手势时,更加的感觉Google的文档写得实在是太差了.很多常量,属性和方法,居然连个描述都没有. 没有描述也就罢了,但是OnGes ...

  8. cocos2d-x入门学习笔记,主要介绍cocos2d-x的基本结构,并且介绍引擎自带的示例

    cocos2d-x 3.0 制作横版格斗游戏 http://philon.cn/post/cocos2d-x-3.0-zhi-zuo-heng-ban-ge-dou-you-xi http://blo ...

  9. 【SPOJ283】Naptime

    题目大意:给定一个由 N 个点组成的环,点有点权,现从中选出 M 个点,对于顺时针方向来说,每一段被选取的第一个点的点权不计入答案贡献,求选出的最大权值是多少. 题解:首先考虑线性的情况,设 \(dp ...

  10. java配置、IntelliJ IDEA Ultimate激活、

    1.下载并安装 Java地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html IntelliJ IDEA地址:ht ...