spoj gss1 gss3
spoj gss系列=最大字段和套餐
gss1就是gss3的无单点修改版
有区间查询和单点修改,考虑用线段树维护
我们要维护区间权值和\(s\),区间最大前缀和\(xl\)和最大后缀和\(xr\),以及最大子段和\(x\)
在pushup的时候,这样维护 代码里有
\]
其实是懒得写文字
// 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的更多相关文章
- SPOJ GSS1 && GSS3 (无更新/更新单点,并询问区间最大连续和)
http://www.spoj.com/problems/GSS1/ 题意:无更新询问区间最大连续和. 做法:线段树每个节点维护sum[rt],maxsum[rt],lsum[rt],rsum[rt] ...
- SPOJ - GSS1&&GSS3
GSS1 #include<cstdio> #include<iostream> #define lc k<<1 #define rc k<<1|1 u ...
- SPOJ GSS1 & GSS3&挂了的GSS5
线段树然后yy一下,搞一搞. GSS1: 题意:求最大区间和. #include <cstdio> #include <algorithm> using namespace s ...
- 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]| ≤ ...
- [题解] SPOJ GSS1 - Can you answer these queries I
[题解] SPOJ GSS1 - Can you answer these queries I · 题目大意 要求维护一段长度为 \(n\) 的静态序列的区间最大子段和. 有 \(m\) 次询问,每次 ...
- GSS系列(1)——GSS1&&GSS3
题意:询问一个区间内的最大连续子段和(GSS1),并且有单点修改的操作(GSS2). 思路:这个题目在老人家的大白鼠里出现过,不过那个是求两个下标,并且相同取更小值.——传的东西更多,判断也稍微繁琐一 ...
- SPOJ - GSS1 —— 线段树 (结点信息合并)
题目链接:https://vjudge.net/problem/SPOJ-GSS1 GSS1 - Can you answer these queries I #tree You are given ...
- 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 ...
- SPOJ GSS1 Can you answer these queries I
Time Limit: 115MS Memory Limit: 1572864KB 64bit IO Format: %lld & %llu Description You are g ...
随机推荐
- python之打印日志logging
import logging # 简单打印日志举例 logging.basicConfig(level=logging.DEBUG) # 设置日志级别,WARN logging.warning('Wa ...
- CSS实现垂直居中的5种思路
前面的话 相对于水平居中,人们对于垂直居中略显为难,大部分原因是vertical-align不能正确使用.实际上,实现垂直居中也是围绕几个思路展开的.本文将介绍关于垂直居中的5种思路 line-hei ...
- Django-website 程序案例系列-1 最简单的web服务器
templates:html模板文件夹下面建立文件login.html <!DOCTYPE html> <html lang="en"> <head& ...
- MT【62】柯西求三角值域
求$sinx(\sqrt{cos^2x+24}-cosx)$的范围. 解答:[-5,5] $$\because (sinx \sqrt{cos^2x+24}-cosxsinx)^2$$ $$\le ( ...
- 洛谷P1516 青蛙的约会(扩展欧几里德)
洛谷题目传送门 很容易想到,如果他们相遇,他们初始的位置坐标之差\(x-y\)和跳的距离\((n-m)t\)(设\(t\)为跳的次数)之差应该是模纬线长\(l\)同余的,即\((n-m)t\equiv ...
- 自学Python2.9-循环(while、for)
自学Python之路 自学Python2.9-循环(while.for) 1. while循环 Python中while语句的一般形式: while 判断条件: 语句 作用:提高开发效率,提高代码重用 ...
- 【BZOJ4820】[SDOI2017]硬币游戏(高斯消元)
[BZOJ4820][SDOI2017]硬币游戏(高斯消元) 题面 BZOJ 洛谷 题解 第一眼的感觉就是构\(AC\)自动机之后直接高斯消元算概率,这样子似乎就是\(BZOJ1444\)了.然而点数 ...
- luogu1970 花匠(dp)
设f1[i]表示以1..i中某个合法序列的长度,而且最后一位是较大的 f2[i]表示以1..i中某个合法序列的长度,而且最后一位是较小的 那么就有$f1[i]=max\{f2[j]+1\},(j< ...
- HDU 1176 免费馅饼 (动态规划)
HDU 1176 免费馅饼 (动态规划) Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼 ...
- 转载:Windows下stdlib.h与glut.h中exit()函数重复定义的解决方案
最近用到 OpenGL的第三方库Glut,碰到了exit()这个函数在stdlib.h与glut.h两个头文件中重复定义的情况,解决方案如下: 打开glut.h,找到exit()函数定义的地方(144 ...