POJ 1754 Splay】的更多相关文章

单点更新,区间最值,用来练Splay刚好. 将位置作为排序的规则,利用Splay不会改变顺序的特点,求某一段区间[l,r]的最值时,将l-1伸展到根,将r+1伸展到l-1的右子树,这时r+1的左子树就是要求的区间.维护一个最值即可. #include<stdio.h> #include<string.h> #include<iostream> using namespace std; ,INF=0x3f3f3f3f; ],fa[N],id,root; int data[…
题目:http://poj.org/problem?id=3580   SuperMemo Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 13105   Accepted: 4104 Case Time Limit: 2000MS Description Your friend, Jackson is invited to a TV show called SuperMemo in which the participa…
最后撸一发splay. 之前用treap撸的,现在splay也找到感觉了,果然不同凡响,两者之间差别与精妙之处各有其精髓! 真心赞一个! POJ平衡树的题目还是比较少,只能挑之前做过的捏一捏.但是收获很多,这一天做的题都是有一定普遍性的. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cstdlib> #include…
Hotel Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12446   Accepted: 5363 Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie…
前几天用treap写了这一题,不过treap支持的操作不如splay的多,作为一个完美主义者,重新用splay写了这一题. splay大部分操作可以通过 强大到无与伦比的数据结构splay-tree 然后根据其中步骤写出来. 一定要注意的一点:几乎所有操作的背后,都要splay(x, 0)一下. 一开始我还以为只是一种打乱,或者是一种取巧的方法,但实际上这样做是为了将双旋的优势体现出来,能够保证当前节点的祖先能够之后查询的时候均摊为O(lgn) 此处需要格外注意. 若不加绝壁超时. #inclu…
大二上的时候.写过一个AVL的操作演示,今天一看Splay.发现和AVL事实上一样,加上线段树的基础,懒惰标记什么都知道.学起来轻松很多哦 我參考的模板来自这里  http://blog.csdn.net/u013480600/article/list/2 里面有大量的ch[r][0] ch[r][1]等 我建议用宏定义代替,写的时候方括号少打了非常多,等做的题多得时候,我再把自己使用的模板发来 #include <cstdio> #include <cstring> #inclu…
题意:与区间查询点更新,点有20W个,询问区间的最大值.曾经用线段树,1000+ms,今天的伸展树,890没ms,差不多. 第一次学习伸展树,一共花了2个单位时间,感觉伸展树真很有用,也很好玩.现在只学了一点点.切个点更新试试. 大致思路:用编号(数组)作为树的键值建树,每插一个数,沿路节点更新最大值(每个结点有一个附加信息标记以之为子树的树所有点的最大值).所以,查询时[i,j],只要把i-1伸展到树根,把j+1伸展到I-1下面,那么j+1的左子树就是要的区间了!查该子树根值信息即可(特判端点…
Double Queue 默写splay板子 很多细节问题... #include<cstdio> #include<iostream> using namespace std; #define maxn 1000005 int root; ; ],par[maxn]; int cnt[maxn],size[maxn]; int val[maxn],dat[maxn]; void pushup(int x) { size[x]=cnt[x]+size[ch[x][]]+size[c…
e,应该是线段树里的水题.线段树单点更新.查询区间最值. 代码套用模板 PS :模板有些地方不太懂. #include<stdio.h>#include<iostream>#include<string.h>#define maxn 200010using namespace std; int val[maxn]; struct Node{    int max;  // 需要求最值这里就改成最值    int left, right;}tree[maxn*4]; //…
Treap树 核心是 利用随机数的二叉排序树的各种操作复杂度平均为O(lgn) Treap模板: #include <cstdio> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <cstdlib> #include <cmath> #include <utility> #include…