SP1716 GSS3 - Can you answer these queries III 题意翻译 n 个数,q 次操作 操作0 x y把A_xAx 修改为yy 操作1 l r询问区间[l, r] 的最大子段和 依旧是维护最大子段和,还是再敲一遍比较好. code: #include<iostream> #include<cstdio> #define ls(o) o<<1 #define rs(o) o<<1|1 using namespace std…
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…
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&…
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…
gss2调了一下午,至今还在wa... 我的做法是:对于询问按右区间排序,利用splay记录最右的位置.对于重复出现的,在splay中删掉之前出现的位置所在的节点,然后在splay中插入新的节点.对于没有出现过的,直接插入.询问时直接统计区间的最大子段和. gss2没能调出bug,所以看了一下以下的gss3,发现跟gss1基本一样.直接上代码 以上的做法是错的,对于这种数据就过不了.姿势不对,囧 44 -2 3 -211 4 GSS Can you answer these queries II…
GSS3 Description 动态维护最大子段和,支持单点修改. Solution 设 \(f[i]\) 表示以 \(i\) 为结尾的最大子段和, \(g[i]\) 表示 \(1 \sim i\) 的最大子段和,那么 \[f[i] = max(f[i - 1] + a[i], a[i])\] \[g[i] = max(g[i - 1], f[i])\] 发现只跟前一项有关.我们希望使用矩阵乘法的思路,但是矩阵乘法通常只能适用于递推问题.因此我们引入广义矩阵乘法. 矩阵乘法问题可分治的原因在于…
SP2713 GSS4 - Can you answer these queries IV 「题意」: n 个数,每个数在\(10^{18}\) 范围内. 现在有「两种」操作 0 x y把区间\([x,y]\) 内的每个数开方 1 x y询问区间\([x,y]\) 的每个数的和 「格式」: 有多组数据,数据以EOF结束,对于每组数据,输出数据的序号,每组数据之后输出一个空行. 「注意」: 不保证给出的区间\([x, y]\) 有x<=y ,如果x>y 请交换x ,y . 之前做过花神那个题,但…
SP1043 GSS1 - Can you answer these queries I 题目描述 给出了序列A[1],A[2],-,A[N]. (a[i]≤15007,1≤N≤50000).查询定义如下: 查询(x,y)=max{a[i]+a[i+1]+...+a[j]:x≤i≤j≤y}. 给定M个查询,程序必须输出这些查询的结果. 输入输出格式 输入格式: 输入文件的第一行包含整数N. 在第二行,N个数字跟随. 第三行包含整数M. M行跟在后面,其中第1行包含两个数字xi和yi. 输出格式:…
题意翻译 nnn 个数, qqq 次操作 操作0 x y把 AxA_xAx​ 修改为 yyy 操作1 l r询问区间 [l,r][l, r][l,r] 的最大子段和 感谢 @Edgration 提供的翻译 题目描述 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:…
\[ Preface \] 没有 Preface. \[ Description \] 维护一个长度为 \(n\) 的数列 \(A\) ,需要支持以下操作: 0 x y 将 \(A_x\) 改为 \(y\) . 1 x y 求 \(\max\limits_{x \leq l \leq r \leq y}{\sum_{i=l}^rA[i]}\) . \[ Solution \] 区间最大子段和 是一个非常经典的问题. 对于 整体最大子段和 来说,一般有 \(O(n)\) 的 贪心 和 分治 做法,…
题面 题解 相信大家写过的传统做法像这样:(这段代码蒯自Karry5307的题解) struct SegmentTree{ ll l,r,prefix,suffix,sum,maxn; }; //... inline void update(ll node) { ll res; tree[node].sum=tree[node<<1].sum+tree[(node<<1)|1].sum; tree[node].maxn=max(tree[node<<1].maxn,tr…
线段树操作. 维护一个区间最大连续子段和,左最大连续子段和,右最大连续子段和即可. 最后不知道怎么搞,query的时候返回了个结构体. #include <cstdio> #include <cstring> #include <iostream> using namespace std; const int N=50005; int n,q,a[N],opt,x,y; struct Segtree{int l,r,lmx,rmx,mx,sum;}t[N<<…
题目链接 之前用线段树写了一遍,现在用\(ddp\)再写一遍. #include <cstdio> #define lc (now << 1) #define rc (now << 1 | 1) inline int max(int a, int b){ return a > b ? a : b; } const int INF = 2147483647 >> 2; const int MAXN = 50010; inline int read(){…
题目描述 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\{…
传送门 Luogu 解题思路 区间最大子段和板子题. 考虑用线段树来做. 对于一个线段树节点所包含区间,它的最大子段和有两种情况,包含中点与不包含. 不包含的情况直接从左右子树转移. 对于包含的情况: 我们对每个节点维护两个值:开头是左端点的最大子段和,结尾是右端点的最大子段和. 那么包含中点的情况可以用上面两个东西转移. 那么这两个东西又怎么维护呢... 他们也有包含与不包含中点的情况,只要记一下节点的区间和就可以了,具体方法同上. 于是便搞定了这道题. 细节注意事项 咕咕咕 参考代码 #in…
题目链接 给出n个数, 2种操作, 一种是将第x个数改为y, 第二种是询问区间[x,y]内的最大连续子区间. 开4个数组, 一个是区间和, 一个是区间最大值, 一个是后缀的最大值, 一个是前缀的最大值. 合并起来好麻烦...... #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <…
问题描述 [LG-SP1716](https://www.luogu.org/problem/SP1716] 题解 GSS 系列的第三题,在第一题的基础上带单点修改. 第一题题解传送门 在第一题的基础上,增加一个单点修改就完事了. \(\mathrm{Code}\) #include<bits/stdc++.h> using namespace std; template <typename Tp> void read(Tp &x){ x=0;char ch=1;int f…
题意翻译 nnn 个数, qqq 次操作 操作0 x y把 AxA_xAx​ 修改为 yyy 操作1 l r询问区间 [l,r][l, r][l,r] 的最大子段和 题目描述 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 ele…
# 题目大意 GSS3 - Can you answer these queries III 需要你维护一种数据结构,支持两种操作: 单点修改 求一个区间的最大子段和 # 解题思路 一个区间的最大子段和(GSS),只能通过三种方式转移而来. 左儿子的最大子段和 右儿子的最大子段和 左儿子的最大右子段和+右儿子的最大左子段和 那这就比较好办了.只需要维护四个东西就可以了 sum,区间和 gss,最大子段和 gssl,最大左子段和 gssr,最大右子段和 emmm,比较可做. # 代码 #inclu…
GSS7Can you answer these queries VII 给出一棵树,树的节点有权值,有两种操作: 1.询问节点x,y的路径上最大子段和,可以为空 2.把节点x,y的路径上所有节点的权值置为c 分析: 修改树路径的信息,可以考虑一下树链剖分.动态树. 这题可以用树链剖分的方式来做,不会的可以看看这篇 树链剖分---模板.其实树链剖分不难理解,一小时左右就能学会了. 对于在一段区间的最大子段和问题,可以参考GSS1 spoj 1043 Can you answer these qu…
Can you answer these queries III(luogu) Description 维护一个长度为n的序列A,进行q次询问或操作 0 x y:把Ax改为y 1 x y:询问区间[l,r]的最大子段和 数据范围:n,q<=5e4,-1e4<=Ai<=1e4; Solution 线段树处理区间最大子段和 res为区间最大子串和 sum为区间和 prel和prer分别为从区间左端点和右端点开始的最大子串和 Code #include <cstdio> #incl…
[题解] 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)\). 当然这么想…
Can you answer these queries III 题目:洛谷 SPOJ [题目描述] 给定长度为N的数列A,以及M条指令,每条指令可能是以下两种之一: 1.“0 x y”,把A[x]改成y: 2.“1 x y”,查询区间[x,y]中的最大连续子段和. [输入格式] 第一行,N: 第二行,N个数,即A[1]...A[N]: 第三行,M: 第4至第M+3行,每行三个整数,分别表示“0或1”,x,y,即指令. [输出格式] i行,i表示“1 x y”的数量,每行1个整数,即指令2的答案…
Can you answer these queries II Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 https://www.spoj.com/problems/GSS2/ Description Being a completist and a simplist, kid Yang Zhe cannot solve but get Wrong Answer from most of the OI problems. And he refuse…
2482: [Spoj1557] Can you answer these queries II Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 145  Solved: 76[Submit][Status][Discuss] Description 给定n个元素的序列. 给出m个询问:求l[i]~r[i]的最大子段和(可选空子段). 这个最大子段和有点特殊:一个数字在一段中出现了两次只算一次. 比如:1,2,3,2,2,2出现了3次,但只算一次,…
1557. Can you answer these queries II Problem code: GSS2 Being a completist and a simplist, kid Yang Zhe cannot solve but get Wrong Answer from most of the OI problems. And he refuse to write two program of same kind at all. So he always failes in co…
GSS2 - Can you answer these queries II #tree Being a completist and a simplist, kid Yang Zhe cannot solve but get Wrong Answer from most of the OI problems. And he refuse to write two program of same kind at all. So he always failes in contests. When…
题目链接:http://www.spoj.com/problems/GSS5/ 题意:给出一个数列.每次查询最大子段和Sum[i,j],其中i和j满足x1<=i<=y1,x2<=j<=y2,x1<=x2,y1<=y2. 思路:线段树的节点[L,R]保存LMax,RMax,Max,sum,表示左起最大值.右起最大值.区间最大值.区间数字和.更新比较简单.下面说查询.另外设置三个函数,可以查询任意区间[L,R]的最大值,以L开始向右最多到R的最大值.以R开始向左最多到L的最…
[题目分析] 问题放到了树上,直接链剖+线段树搞一搞. 调了300行+. (还是码力不够) [代码] #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <map> #include <set> #include <queue> #include <string> #include <iostr…