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…
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{…
# 题目大意 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…
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…
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 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…
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次,但只算一次,…
4487. Can you answer these queries VI Problem code: GSS6 Given a sequence A of N (N <= 100000) integers, you have to apply Q (Q <= 100000) operations: Insert, delete, replace an element, find the maximum contiguous(non empty) sum in a given interval…
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…
Can you answer these queries VI Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on SPOJ. Original ID: GSS664-bit integer IO format: %lld      Java class name: Main Given a sequence A of N (N <= 100000) integers, you have to appl…
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: 直接计…
今天下午不知道要做什么,那就把gss系列的线段树刷一下吧. Can you answer these queries I 题目:给出一个数列,询问区间[l,r]的最大子段和 分析: 线段树简单区间操作. 线段树中记录lx,rx,mx,分别表示:最大前驱连续和,最大后继连续和,区间最大子段和. 在合并时时只需要合并两个区间即可,具体可以看代码的Union. 从队友jingo那里学到了这种合并的写法,发现比网上大部分代码简单很多. #include <set> #include <map&g…
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…
题目链接 给出n个数, 2种操作, 一种是将第x个数改为y, 第二种是询问区间[x,y]内的最大连续子区间. 开4个数组, 一个是区间和, 一个是区间最大值, 一个是后缀的最大值, 一个是前缀的最大值. 合并起来好麻烦...... #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <…
[题目分析] GSS1的基础上增加修改操作. 同理线段树即可,多写一个函数就好了. [代码] #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <map> #include <set> #include <queue> #include <string> #include <iostream&…
Time Limit: 1000MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu 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 to write two program of same kind at…
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+…
题目链接: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的最…
GSS1 线段树最大子段和裸题,不带修改,注意pushup. 然而并不会猫树之类的东西 #include<bits/stdc++.h> #define MAXN 50001 using namespace std; struct node{ int l , r , sum , lMax , rMax , midMax; }Tree[MAXN << ]; int a[MAXN] , rMax , allMax , N; inline int max(int a , int b){ r…
题意翻译 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…
题意翻译 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:…
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])\] 发现只跟前一项有关.我们希望使用矩阵乘法的思路,但是矩阵乘法通常只能适用于递推问题.因此我们引入广义矩阵乘法. 矩阵乘法问题可分治的原因在于…
题目链接 这一道题的修改操作用平衡树都很容易实现,难处理的是询问操作. 要想解决询问操作,只要知道如何在平衡树上快速合并左右两个区间的答案即可. 设$Ans_{[l,r]}^k=\sum\limits_{i=l}^rA(i)\cdot(i-l+1)^k$. 设现在要处理的区间为$[x,y]$,中间位置为$mid$,已知$Ans_{[x,mid-1]}^k$和$Ans_{[mid+1,y]}^k$,要求$Ans_{[x,y]}^k$. 显然,$Ans_{[x,y]}^k=Ans_{[x,mid-1…
Time Limit: 500MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Description You are given a sequence A of N(N <= 100,000) positive integers. There sum will be less than 1018. On this sequence you have to apply M (M <= 100,000) operati…
题目链接:点击打开链接 题意: 给定n长的序列 以下2个操作 0 x y 给[x,y]区间每一个数都 sqrt 1 x y 问[x, y] 区间和 #include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <queue> #include <math.h> #include <vector> #inclu…
题面 题解 相信大家写过的传统做法像这样:(这段代码蒯自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…