板的不能再板,链剖+线段树或者是LCT随便维护. 感觉唯一要注意的是跳链的时候要对$x$向上跳和$y$向上跳的情况分开讨论,而不能直接$swap$,因为只有两段接触的端点才能相互合并,而且每一次向上跳的线段要放在已经合并完成之后的左端. 最后输出答案的时候要注意这时候$x$和$y$合并好的树链上其实左端点都是在上面的,而$x$和$y$其实是左端点相接触的,所以最后合并的时候$x.lmax + y.lmax$可能成为最优答案而不是$x.rmax + y.lmax$. 一开始线段树写手残了…… 时间…
[题目分析] 问题放到了树上,直接链剖+线段树搞一搞. 调了300行+. (还是码力不够) [代码] #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <map> #include <set> #include <queue> #include <string> #include <iostr…
GSS7Can you answer these queries VII 给出一棵树,树的节点有权值,有两种操作: 1.询问节点x,y的路径上最大子段和,可以为空 2.把节点x,y的路径上所有节点的权值置为c 分析: 修改树路径的信息,可以考虑一下树链剖分.动态树. 这题可以用树链剖分的方式来做,不会的可以看看这篇 树链剖分---模板.其实树链剖分不难理解,一小时左右就能学会了. 对于在一段区间的最大子段和问题,可以参考GSS1 spoj 1043 Can you answer these qu…
纯数据结构题,没有思维难度.直接用线段树求最大子段和的方法完成树上路径的合并.注意链上合并顺序要符合序列的前后顺序. #include <cstdio> #include <cstring> #define cd w<<1 const int S=200030; int n,Q,h[S],v[S],nx[S],d[S],e[S],s[S],eg=1,fa[S],t[S],f[S],_=0,rk[S],a[S],dep[S]; inline int ma(int a,in…
题目传送门 题目大意 给出一个\(n\)个点的树,每个点有权值.有\(m\)次操作,每次要么查询一条链上的最大子段和,要么把一条链的权值都修改为一个常数. \(n,m\le 10^5\) 思路 如果是一维的话,我们不难列出动态\(\texttt{dp}\)转移式: \[\begin{bmatrix}0&a_i&0\\-\infty&a_i&0\\-\infty&-\infty&0\end{bmatrix}\begin{bmatrix}g_{i-1}\\f_{…
水题,只是坑点多,\(tag\)为\(0\)时可能也要\(pushdown\),所以要\(bool\)标记是否需要.最后树链剖分询问时注意线段有向!!! #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <iostream> #include <numeric> #define R(a,b,c) for(registe…
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…
[题解] 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 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…
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…
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: 直接计…
gss2调了一下午,至今还在wa... 我的做法是:对于询问按右区间排序,利用splay记录最右的位置.对于重复出现的,在splay中删掉之前出现的位置所在的节点,然后在splay中插入新的节点.对于没有出现过的,直接插入.询问时直接统计区间的最大子段和. gss2没能调出bug,所以看了一下以下的gss3,发现跟gss1基本一样.直接上代码 以上的做法是错的,对于这种数据就过不了.姿势不对,囧 44 -2 3 -211 4 GSS Can you answer these queries II…
今天下午不知道要做什么,那就把gss系列的线段树刷一下吧. Can you answer these queries I 题目:给出一个数列,询问区间[l,r]的最大子段和 分析: 线段树简单区间操作. 线段树中记录lx,rx,mx,分别表示:最大前驱连续和,最大后继连续和,区间最大子段和. 在合并时时只需要合并两个区间即可,具体可以看代码的Union. 从队友jingo那里学到了这种合并的写法,发现比网上大部分代码简单很多. #include <set> #include <map&g…
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{…
Given a tree with N ( N<=100000 ) nodes. Each node has a interger value x_i ( |x_i|<=10000 ). You have to apply Q ( Q<=100000 ) operations: 1. 1 a b : answer the maximum contiguous sum (maybe empty,will always larger than or equal to 0 ) from the…
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…
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: 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: 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…
题目链接: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…
题目链接 这一道题的修改操作用平衡树都很容易实现,难处理的是询问操作. 要想解决询问操作,只要知道如何在平衡树上快速合并左右两个区间的答案即可. 设$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…
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个操作 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…