SPOJ GSS1 & GSS3&挂了的GSS5】的更多相关文章

线段树然后yy一下,搞一搞. GSS1: 题意:求最大区间和. #include <cstdio> #include <algorithm> using namespace std; int lm[200005],rm[200005],ma[200005],s[200005],left,right,n,m,ans,rans; void build(int l,int r,int num){ if(l==r){scanf("%d",&ma[num]);rm…
传送门 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[r…
http://www.spoj.com/problems/GSS1/ 题意:无更新询问区间最大连续和. 做法:线段树每个节点维护sum[rt],maxsum[rt],lsum[rt],rsum[rt],分别区间和.区间最大和.区间左端最大和和区间右端最大和. 查询时按从左到右扫,维护ans为最大连续和,rans为到该段的右端最大连续和,扫到每一段时有: ans = max(ans,maxsum[rt]); ans = max(ans,rans+lsum[rt]); rans = max(rsum…
GSS1 #include<cstdio> #include<iostream> #define lc k<<1 #define rc k<<1|1 using namespace std; ,N=M<<; struct sgt{ int sum,gss,lgss,rgss; }tr[N]; int n,m,a[N]; void updata(int k){ tr[k].sum=tr[lc].sum+tr[rc].sum; tr[k].lgss=…
Can you answer these queries I SPOJ - GSS1 You are given a sequence A[1], A[2], -, A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A query is defined as follows: Query(x,y) = Max { a[i]+a[i+1]+-+a[j] ; x ≤ i ≤ j ≤ y }. Given M queries, your program must o…
[题解] SPOJ GSS1 - Can you answer these queries I · 题目大意 要求维护一段长度为 \(n\) 的静态序列的区间最大子段和. 有 \(m\) 次询问,每次询问输出区间 \([L,R]\) 的最大子段和. \(|a[i]| \leq 15007\),\(1 \leq m,n\leq5\times10^4\) · 解题思路 首先想到如果用线段树的方法,那么预处理时间复杂度为\(O(n)\),总询问复杂度为\(O(m\cdot logn)\). 当然这么想…
题意:询问一个区间内的最大连续子段和(GSS1),并且有单点修改的操作(GSS2). 思路:这个题目在老人家的大白鼠里出现过,不过那个是求两个下标,并且相同取更小值.——传的东西更多,判断也稍微繁琐一些... 考虑我们平时如何处理最大连续子段和——O(n)DP,然而显然在一个时刻会修改的序列上无法实现.我们至少需要一个O(nlgn)的算法.考虑到这种连续的和可以对应线段树的一些操作,我们就将它应用到线段树上. 老人家在讲子段和的时候提供了一种分治算法——如果将一段序列分成两端,那么它的最大子段和…
题目链接:https://vjudge.net/problem/SPOJ-GSS1 GSS1 - Can you answer these queries I #tree You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A query is defined as follows: Query(x,y) = Max { a[i]+a[i+1]+...+a[j] ; x ≤ i…
Description You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A query is defined as follows: Query(x,y) = Max { a[i]+a[i+1]+...+a[j] ; x ≤ i ≤ j ≤ y }. Given M queries, your program must output the results of these…
Time Limit: 115MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Description You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A query is defined as follows: Query(x,y) = Max { a[i]+a[i+1]+...+a[j] ; x ≤ i…
题目大意: 给定n个数,再给q个区间询问,希望在区间s,t中找到一段连续的子序列使其和最大 因为询问上万,节点数50000,明显是用线段树去做,这里很明显的区间更新,唯一写起来有点恶心的是询问 每一个区间的最大都要跟左右区间的左最大右最大有关系 反正时要注意细节了,查询的时候同时要查询其左右连续最大 自己的错误在于左右连续最大的更新出问题,这个希望自己以后要注意 #include <cstdio> #include <cstring> #include <iostream&g…
题目链接 给出n个数, 2种操作, 一种是将第x个数改为y, 第二种是询问区间[x,y]内的最大连续子区间. 开4个数组, 一个是区间和, 一个是区间最大值, 一个是后缀的最大值, 一个是前缀的最大值. 合并起来好麻烦...... #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <…
[题目分析] 线段树裸题. 注意update的操作,写结构体里好方便. 嗯,没了. [代码] #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <map> #include <set> #include <queue> #include <string> #include <iostream&…
You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A query is defined as follows: Query(x,y) = Max { a[i]+a[i+1]+...+a[j] ; x ≤ i ≤ j ≤ y }. Given M queries, your program must output the results of these queries. Inp…
SPOJ GSS1 题意:给一个序列以及一些询问,每个是问\([l,r]\)中最大连续子序列和是多少. 思路:这个问题是以下问题的基础. 我们考虑用线段树来解决这个问题. 首先我们来想想如果要求出最大连续子序列和需要什么信息. 对于\([l,m)\)和\([m,r)\)这两个区间,我们需要将它们合并成\([l,r)\)这个区间. 那么我们考虑分治地来解决这个问题.把问题分成三部分: \([l,m)\)中的最大子序列和 \([m,r)\)中的最大子序列和 左端点在\([l,m)\)内,右端点在\(…
SPOJ - GSS1:https://vjudge.net/problem/SPOJ-GSS1 参考:http://www.cnblogs.com/shanyr/p/5710152.html?utm_source=itdadao&utm_medium=referral 题意: 给定一个数列,很多次询问,问某个区间中最大的连续和是多少. 思路 线段树,每个线段树的节点要维护对应区间的最大值ans,与左端点相连的最大值lv,与右端点相连的最大值rv,还有区间全部的总和V: 这个V用在pushup中…
目录 Noip 训练指南 图论 数据结构 位运算 期望 题解 Noip 训练指南 目前完成 \(4 / 72\) 图论 [ ] 跳楼机 [ ] 墨墨的等式 [ ] 最优贸易 [ ] 泥泞的道路 [ ] BZOJ2959 [ ] BZOJ2535 数据结构 [ ] luog 2572 [SCOI2010]序列操作 [ ] luogu2184 [ ] cf620E New year tree [ ] GSS1 [ ] GSS3 [ ] GSS4 [ ] HDU6315 [ ] luogu2073 […
1858: [Scoi2010]序列操作 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 3397 Solved: 1624 [Submit][Status][Discuss] Description lxhgww最近收到了一个01序列,序列里面包含了n个数,这些数要么是0,要么是1,现在对于这个序列有五种变换操作和询问操作: 0 a b 把[a, b]区间内的所有数全变成0 1 a b 把[a, b]区间内的所有数全变成1 2 a b 把[a,b]…
gss2调了一下午,至今还在wa... 我的做法是:对于询问按右区间排序,利用splay记录最右的位置.对于重复出现的,在splay中删掉之前出现的位置所在的节点,然后在splay中插入新的节点.对于没有出现过的,直接插入.询问时直接统计区间的最大子段和. gss2没能调出bug,所以看了一下以下的gss3,发现跟gss1基本一样.直接上代码 以上的做法是错的,对于这种数据就过不了.姿势不对,囧 44 -2 3 -211 4 GSS Can you answer these queries II…
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50000) integers between -10000 and 10000. On this sequence you have to apply M (M <= 50000) operations: modify the i-th element in the sequence or for giv…
gss5 Can you answer these queries V 给出数列a1...an,询问时给出: Query(x1,y1,x2,y2) = Max { A[i]+A[i+1]+...+A[j] ; x1 <= i <= y1 , x2 j <= y2 and x1 <= x2 , y1 <= y2 } 分析: 其实画个图分类讨论一下之后,跟gss1基本一样... 注意到x1<=x2 , y1<=y2. 所以大致可以分为: 1.y1<x2: 直接计…
GSS5 - Can you answer these queries V #tree You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| <= 10000 , 1 <= N <= 10000 ). A query is defined as follows: Query(x1,y1,x2,y2) = Max { A[i]+A[i+1]+...+A[j] ; x1 <= i <= y1 , x2 <= j…
GSS3 - Can you answer these queries III You are given a sequence A of N (N <= 50000) integers between -10000 and 10000. On this sequence you have to apply M (M <= 50000) operations: modify the i-th element in the sequence or for given x y print max{…
[题目分析] GSS1上增加区间左右端点的限制. 直接分类讨论就好了. [代码] #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <map> #include <set> #include <queue> #include <string> #include <iostream> #i…
[题目分析] GSS1的基础上增加修改操作. 同理线段树即可,多写一个函数就好了. [代码] #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <map> #include <set> #include <queue> #include <string> #include <iostream&…
# 题目大意 GSS3 - Can you answer these queries III 需要你维护一种数据结构,支持两种操作: 单点修改 求一个区间的最大子段和 # 解题思路 一个区间的最大子段和(GSS),只能通过三种方式转移而来. 左儿子的最大子段和 右儿子的最大子段和 左儿子的最大右子段和+右儿子的最大左子段和 那这就比较好办了.只需要维护四个东西就可以了 sum,区间和 gss,最大子段和 gssl,最大左子段和 gssr,最大右子段和 emmm,比较可做. # 代码 #inclu…
SPOJ GSS系列真是有毒啊! 立志刷完,把线段树搞完! 来自lydrainbowcat线段树上的一道例题.(所以解法参考了lyd老师) 题意翻译 n 个数, q 次操作 操作0 x y把 Ax 修改为 y 操作1 l r询问区间 [l,r] 的最大子段和 数据规模在50000,有负数. 冷静分析 因为要维护最大子段和,那么我们可以在线段树struct中维护这么几个信息: sum(区间和).lmax(从左顶点出发的最大子段和).rmax(从右顶点出发的最大子段和).maxx(这段的最大子段和)…
传送门 解题思路 和GSS1相似,但需要巨恶心的分类讨论,对于x1<=y1< x2< =y2 这种情况 , 最大值应该取[x1,y1]的右端最大+[y1+1,x2-1]的和+[x2,y2]的左端最大.对于x1< =x2< =y1<=y2,用四种情况,第一种是[x1,x2-1]的右端最大+[x2,y2]的左端最大,第二种是[x1,y1]的右端最大+[y1+1,y2]的左端最大,第三种是[x2,y1]的最大值,第四种是[x1,x2-1]的右端最大+[x2,y1]的和+[y1…
Time Limit: 132MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Description You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| <= 10000 , 1 <= N <= 10000 ). A query is defined as follows: Query(x1,y1,x2,y2) = Max { A[i]+A[i+…
Time Limit: 330MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Description You are given a sequence A of N (N <= 50000) integers between -10000 and 10000. On this sequence you have to apply M (M <= 50000) operations: modify the i-th…