BZOJ.4355.Play with sequence(线段树)】的更多相关文章

题目链接 问题在于操作二.操作二可以拆分成:区间加\(C\).区间(对\(0\))取\(\max\). 注意到操作一的\(C\)都是非负数,即数列中不会出现负数,所以我们直接维护最小值和最小值出现的次数即可得到操作三的答案. 操作一的赋值和操作二的加都是模板.但是取\(\max\)会影响最小值的个数(某些\(>mn\)的值可能一起变成最小值). 参照吉司机线段树,我们还需要维护严格次小值\(se\). 进行\(\max(v)\)操作时,若\(mn[rt]\geq v\),则直接返回:若\(se[…
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: Yuta has an array A with n numbers. Then he make…
[BZOJ 1483] [HNOI2009] 梦幻布丁 (线段树合并) 题面 N个布丁摆成一行,进行M次操作.每次将某个颜色的布丁全部变成另一种颜色的,然后再询问当前一共有多少段颜色.例如颜色分别为1,2,2,1的四个布丁一共有3段颜色. \(n,m\leq 1 \times 10^5\),颜色编号 \(\leq 1 \times 10^6\) 分析 先考虑询问,我们可以对每种颜色分别求出这种颜色的连续段有多少个.可以用权值线段树实现.第c棵权值线段树维护颜色c的位置出现情况,如果第i个位置颜色…
[BZOJ 2653] middle(可持久化线段树+二分答案) 题面 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b]之间,右端点在[c,d]之间的子序列中,最大的中位数. 其中a<b<c<d. 位置也从0开始标号. 强制在线. 分析 二分答案mid,表示询问的中位数在排过序的整个b序列中是第mid小. 考虑判断一个数是否<=序列的中位数:把大于等于这…
bzoj 1537: [POI2005]Aut- The Bus 先把坐标离散化 设f[i][j]表示从(1,1)走到(i,j)的最优解 这样直接dp::: f[i][j] = max{f[i-1][j] + f[i][j-1]} + w[i][j]就可以完美的MLE + TLE了 我们发现f[i][j]中,只有有权的点才有意义,但是我们只有10^5个有用的点,却考虑了10^5 * 10^5个点 所以我们只考虑有权的点,那么可以发现, f[i][j]的更新一定是由f(1,1)~(i,j)的最大值…
Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 3808 Accepted Submission(s): 1079 Problem Description Recently, Doge got a funny birthday present from his new friend, Protein…
D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/problem/D Description At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important…
题目链接:BZOJ - 3196 题目分析 区间Kth和区间Rank用树状数组套线段树实现,区间前驱后继用线段树套set实现. 为了节省空间,需要离线,先离散化,这样需要的数组大小可以小一些,可以卡过128MB = = 嗯就是这样,代码长度= =我写了260行......Debug了n小时= = 代码 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #in…
Problem Description Recently, Doge got a funny birthday present from his new friend, Protein Tiger from St. Beeze College. No, not cactuses. It's a mysterious blackbox. After some research, Doge found that the box is maintaining a sequence an of n nu…
线段树的合并..对于一个点x, 我们只需考虑是否需要交换左右儿子, 递归处理左右儿子. #include<bits/stdc++.h> using namespace std; #define M(l, r) (((l) + (r)) >> 1) typedef long long ll; ; ; struct Node *null, *pt; struct Node { Node *l, *r; int cnt; Node() : cnt() { l = r = null; }…