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 ...
随机推荐
- Delphi中的构造函数的override的问题
TObject的构造方法Create不能被override.因为它是一个静态方法.
- BZOJ5415[Noi2018]归程——kruskal重构树+倍增+堆优化dijkstra
题目描述 本题的故事发生在魔力之都,在这里我们将为你介绍一些必要的设定. 魔力之都可以抽象成一个 n 个节点.m 条边的无向连通图(节点的编号从 1 至 n).我们依次用 l,a 描述一条边的长度.海 ...
- BZOJ1915[USACO 2010 Open Gold 1.Cow Hopscotch]——DP+斜率优化
题目描述 奶牛们正在回味童年,玩一个类似跳格子的游戏,在这个游戏里,奶牛们在草地上画了一行N个格子,(3 <=N <= 250,000),编号为1..N.就像任何一个好游戏一样,这样的跳格 ...
- POI 生成excel(大数据量) SXSSF
使用POI 的SXSSF (Streaming Usermodel API)生成较大的excel,同时开启压缩 import junit.framework.Assert; import org.ap ...
- Educational Codeforces Round 3 C. Load Balancing
C. Load Balancing time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 一个死循环导致的栈溢出实例:StackOverFlowError
有一个功能,要用复选框组做成单选框效果,如果有三个复选框 CheckBox ,并且保证每次只能选中一个.刚开始添加了以下的值改变后的监听方法 addValueChangeListener ,却导致了栈 ...
- 12 Zabbix Item类型之Zabbix JMX类型
点击返回:自学Zabbix之路 12 Zabbix Item类型之Zabbix JMX类型 JMX 全称是Java Management Extensions,即Java管理扩展.Java程序会开放一 ...
- CRM 2013 批量更新two options的缺省值
1: string entNames = "new_print_plan,new_radio_plan,new_bill_board,new_tv_plan,new_btl_posm,new ...
- 【AGC005F】简单的问题 Many Easy Problems
Description 链接 Solution 对于每个\(k\),统计任选\(k\)个点作为关键点的"最小生成树"的大小之和 正向想法是枚举或者计算大小为\(x\).叶子数目为\ ...
- Looper Handler Mssage
1. 一个Handler只有一个队列;2. 在调用Handler.post(Runnable runnable)方法时,会将runnable封装成一个Message;3. 在队列执行时,会判断当前的M ...