线段树&树状数组&RMQ
Falling~
这个作者很懒,什么都没留下…
展开
-
线段树--hdu4027 Can you answer these queries?
2个操作,一个是求区间和,一个是将区间内所有数开根号。long long 开根号6.7次即可变成1,所以直接单点更新即可。#include #include #include #include using namespacestd;const int maxn =1e5 + 5;typedef long原创 2017-08-17 10:13:52 · 189 阅读 · 0 评论 -
线段树--区间修改--cf1070-c Cloud Computing
n天每天需要k个东西,有m种价格方案:方案i [Li,Ri] 内每天有ci个,每个pi元(如果某天所能获得的东西不足k个,全部借完)求最小花费。解:按价格排序,线段树记录某天已经借了的数量,成段更新。更新时判断,1.如果最小值 >= k,即该区间已经满足条件,不用再借,return2.如果最大值 + c <= k,即该区间全部都可以借c个,利用lazy标记区...原创 2018-10-22 15:09:11 · 405 阅读 · 0 评论 -
数据结构--离线树状数组--hdu4605 Magic Ball Game
n个点的树,每个点有一个权值。1为根,每个点要么有2个儿子,要么没有儿子。Q次询问,每次给节点v,和数X,一个球从根往下走:1.X = w[i]或i没有儿子,球停下2.X < w[i],球有1/2可能往左走,1/2可能右走3.X > W[I],球有1/8可能往左走,7/8可能右走统计根到v的路径上,(往左走、往右走)*(大于x、小于x)的个数则到达v点的可能性为...原创 2018-10-10 19:42:37 · 247 阅读 · 0 评论 -
数据结构--线段树&离散化可能有的问题--poj2528 Mayor's posters
给定n个区间,按顺序覆盖后,问最后几个是可见的。l,r,范围1e7,需要离散化。//但是注意简单的离散化可能会出现错误,给出下面两个简单的例子应该能体现普通离散化的缺陷://例子一:1-10 1-4 5-10//例子二:1-10 1-4 6-10//解决的办法则是对于距离大于1的两相邻点,中间再插入一个点这样离散化后例子一:[1,6] [1,3] [4,6]例子二:...转载 2018-10-12 21:08:32 · 331 阅读 · 0 评论 -
数据结构--线段树--牛客练习赛28B
https://www.nowcoder.com/acm/contest/200/Bop = 1 sumop = 2 sum2 平方和op = 3 *mulop = 4 +add2个lazy标记#include <cstdio>#include <iostream>using namespace std;#define lc (rt <...原创 2018-10-05 23:42:19 · 237 阅读 · 0 评论 -
dfs序+线段树--青出于蓝胜于蓝
https://nanti.jisuanke.com/t/20690武当派一共有 nn 人,门派内 nn 人按照武功高低进行排名,武功最高的人排名第 11,次高的人排名第 22,... 武功最低的人排名第 nn。现在我们用武功的排名来给每个人标号,除了祖师爷,每个人都有一个师父,每个人可能有多个徒弟。我们知道,武当派人才辈出,连祖师爷的武功都只能排行到 pp。也就是说徒弟的原创 2018-01-22 19:55:52 · 793 阅读 · 0 评论 -
线段树--codeforces242E XOR on Segment
给定1e5个数ai操作1,求区间和操作2,将ql,qr区间内所有数与x异或线段树真神奇。。。。 将ai的每一位用线段树表示,20个线段树即可。//又是1e5和线段树//1.r - l + 1//2.pushdown时lc,rc要取反//3.bitset打成10//4.seg,lazy线段树居然没有开#include #原创 2017-11-05 20:42:17 · 222 阅读 · 0 评论 -
线段树--hdu5475 An easy problem
1e5次操作,op = 1,就乘上一个数y(1e9) ,op = 2,就除以第n次乘上的数。求每次操作后对m取余的值。居然是线段树。//线段树 1e5确实看起来像#include #include using namespacestd;#define mid (l + r) / 2#define lc rt 1原创 2017-11-04 21:24:43 · 216 阅读 · 0 评论 -
二维RMQ--poj2019 cornfield
求矩阵中,以给定点(i,j)为左上角的,大小为b * b的矩形内,最大值和最小值的差。ST表#include #include #include using namespacestd;const int maxn =255;int mmax[maxn][maxn][10],mmin[maxn][maxn][原创 2017-11-03 19:46:15 · 224 阅读 · 0 评论 -
稀疏表Sparse Table--uva 11235 Frequent values
#include #include using namespacestd;const int maxn =1e6 + 1;int a[maxn],c[maxn];int maxnum = 1e6;int lowbit(int x) {return x & -x;}int sum(int x){ int res =原创 2017-10-13 20:49:17 · 216 阅读 · 0 评论 -
线段树--区间修改set,区间更新add
//区间置数,设所有set>0,-1表示没有set标记#include #include #include using namespacestd;const int maxn =1e5 + 5;int Min[maxn <<2],Max[maxn <<2],sum[maxn <<2],lazy[maxn <<2];原创 2017-10-20 22:06:12 · 582 阅读 · 0 评论 -
树状数组模版
#include #include using namespacestd;const int maxn =1e6 + 1;int a[maxn],c[maxn];int maxnum = 1e6;int lowbit(int x) {return x & -x;}int sum(int x){ int res =原创 2017-10-13 19:45:51 · 242 阅读 · 0 评论 -
线段树--lazy思想
描述Today HH is palying with a n×n matrix. All the numbers of the matrix is 0 initial, and every time HH will do one of the following things:make all the numbers in the k row become vm原创 2017-05-14 19:47:34 · 298 阅读 · 0 评论 -
线段树--单点更新,区间lazy更新,区间查询
线段树原创 2017-03-18 18:40:52 · 348 阅读 · 0 评论 -
dfs序 树状数组--hdu5927 Auxiliary Set
Given a rooted tree with n vertices, some of the vertices are important. An auxiliary set is a set containing vertices satisfying at least one of the two conditions: ∙∙It is an important ver原创 2017-10-17 20:38:21 · 206 阅读 · 0 评论 -
线段树--求逆序数
#include #include #include using namespacestd;const int maxn =50005;pairint,int> order[maxn];int seg[maxn <<2];void build(int l,int r,int rt)原创 2017-05-25 12:34:46 · 360 阅读 · 0 评论 -
线段树--poj2828 Buy tickets
一开始为空队列,n个人,每次插队在第p个人后面,求最后的位置。当最后一个人插入时,他的位置与最后的结果中的位置相同,可确定,所以倒着求。用线段树记录区间内空格数。#include #include using namespacestd;const int maxn =200000 + 5;int seg[maxn原创 2017-07-26 14:48:06 · 148 阅读 · 0 评论 -
数据结构--线段树--维护等差数列--uva12436 Rip Van Winkle's Code
N=250000op1. 区间[ql,qr] ql的位置+1,ql+1的位置+2。。。op2. 区间[ql,qr] qr的位置+1,qr-1的位置+2。。。op3.区间[ql,qr] 区间修改为xop4.求区间和大佬博客 https://blog.csdn.net/hei_nero/article/details/9798723将梯形划分为左右区间的时候,相当于左区间维护小...转载 2018-10-29 15:35:19 · 535 阅读 · 0 评论