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 ...
随机推荐
- CSS实现水平垂直同时居中的6种思路
前面的话 水平居中和垂直居中已经单独介绍过,本文将介绍水平垂直同时居中的6种思路 水平对齐+行高 [思路一]text-align + line-height实现单行文本水平垂直居中 <style ...
- mysql关于binlog日志的操作
查看binlog日志选项和存储位置: mysql> show variables like 'log_%'; 1.查看所有binlog日志列表 mysql> show master log ...
- BZOJ4946 NOI2017蔬菜(贪心+堆)
容易想到一个费用流做法:将每种蔬菜拆成p种,对应p个过期时间,每一种向可以卖的时间连边,第一次卖的奖励算在最晚过期的一种里.对于天数动态加点.不过这样边数太多了,因为第i天能卖的第i-1天一定能卖,可 ...
- AC自动机-HDU2896-模板题
http://acm.hdu.edu.cn/showproblem.php?pid=2896 另一道AC自动机的模板题,不过这题需要记录一下具体的匹配情况. /*------------------- ...
- Json 转 dynamic
直接上代码: var model = JsonConvert.DeserializeObject<dynamic>("{\"ResponseResult\": ...
- IDEA上传码云报错Push rejected: Push to origin/master was rejected
原因是README.md文件冲突,码云上在创建项目的时候不要初始化README.md,然后再用IDEA上传
- PHP 判断浏览器语言
详情请参看代码 作用:判断当前的浏览器语言.接收传入参数.拼接字符串 <?php $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2); if ...
- BroadcastReceiver 接收系统短信广播
BroadcastReceiver 接收系统短信广播 /* 注册广播: * |--静态注册 (在AndroidManifest .xml 中注册) * <receiver androi ...
- 洛谷 P3965 [TJOI2013]循环格 解题报告
P3965 [TJOI2013]循环格 题目背景 一个循环格就是一个矩阵,其中所有元素为箭头,指向相邻四个格子. 每个元素有一个坐标(行,列),其中左上角元素坐标为\((0,0)\).给定一个起始位\ ...
- cf379F New Year Tree (树的直径+倍增lca)
可以证明,如果合并两棵树,新的直径的端点一定是原来两树中直径的端点 可以把新加两个点的操作看成是把两个只有一个点的树合并到原来的树上,然后用其中的一个点去和原来树上的直径两端点更新直径就可以了 #in ...