POJ - 3481 splay板子】的更多相关文章

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…
最后撸一发splay. 之前用treap撸的,现在splay也找到感觉了,果然不同凡响,两者之间差别与精妙之处各有其精髓! 真心赞一个! POJ平衡树的题目还是比较少,只能挑之前做过的捏一捏.但是收获很多,这一天做的题都是有一定普遍性的. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cstdlib> #include…
2013-08-08 POJ 3481  Double Queue 这个题应该是STL里较简单的吧,用平衡二叉树也可以做,但是自己掌握不够- -,开始想用两个优先队列,一个从大到小,一个从小到大,可是因为它又可能删除优先权最大的,又可能删除优先权最小的,所以当输入为2或者3的时候没办法判断是不是没有顾客了.通过这道题发觉map的其他用法真的是一点不会.所以看了别人的代码用了两种方法试着敲一下,写这个随笔是博客的第一篇文章,内容虽然这么水,但是的确是我之前掌握不好的部分,本菜鸟今天比赛之后受刺激了…
原题 给出一个n个数的数列ai ,对于第i个元素ai定义\(fi=min(|ai-aj|) (1<=j<i)\),f1=a1,求\(/sumfi\) Splay板子题. Splay讲解:http://www.cnblogs.com/mrsheep/p/8110483.html //太懒了-- #include<cstdio> #include<algorithm> #include<cmath> #define which(x) (ls[f[(x)]]==(…
Double Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15786   Accepted: 6998 Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provid…
题目: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…
题目链接: PKU:http://poj.org/problem?id=3481 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1908 Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by…
splay的板子.. 由于被LCT榨干了..所以昨天去学了数组版的splay,现在整理一下板子.. 以BZOJ3224和3223为例题..暂时只有这些,序列的话等有时间把维修序列给弄上来!! BZOJ 3224 平衡树的操作 #include <bits/stdc++.h> #define INF 0x3f3f3f3f #define full(a, b) memset(a, b, sizeof a) using namespace std; typedef long long ll; inl…
开始学习新知识:splay——tree 是个板子题,学习splay可以看博客 https://blog.csdn.net/Clove_unique/article/details/50630280 #include<iostream> #include<cstring> #include<cstdio> using namespace std; #define MAXN 1000000 ],f[MAXN],size[MAXN],cnt[MAXN],key[MAXN];…
单点更新,区间最值,用来练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[…
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…
平衡树.. 熟悉些fhq-Treap,为啥我在poj读入优化不能用啊 #include <iostream> #include <cstdio> #include <ctime> #include <cstdlib> #include <cstring> #define INF 0x3f3f3f3f #define full(a, b) memset(a, b, sizeof a) using namespace std; typedef lon…
1, splay的一些基本操作. 使用前要插入$-INF,+INF$保证每个点的前驱后继存在. $get$函数在$x$存在时, 调用后, 根为$x$, 否则根为$x$的前驱或后继 const int N = 1e6+10; int n, tot, rt, sz; struct { int cnt,sz,fa,ch[2],v; } tr[N]; void pu(int x) { tr[x].sz=tr[tr[x].ch[0]].sz+tr[tr[x].ch[1]].sz+tr[x].cnt; }…
前几天用treap写了这一题,不过treap支持的操作不如splay的多,作为一个完美主义者,重新用splay写了这一题. splay大部分操作可以通过 强大到无与伦比的数据结构splay-tree 然后根据其中步骤写出来. 一定要注意的一点:几乎所有操作的背后,都要splay(x, 0)一下. 一开始我还以为只是一种打乱,或者是一种取巧的方法,但实际上这样做是为了将双旋的优势体现出来,能够保证当前节点的祖先能够之后查询的时候均摊为O(lgn) 此处需要格外注意. 若不加绝壁超时. #inclu…
下面给出Splay的实现方法(复杂度证明什么的知道是 nlogn 就可以啦) 首先对于一颗可爱的二叉查找树,是不能保证最坏nlogn的复杂度(可以想象把一个升序序列插入) (二叉查找树保证左子树元素大小都小于根元素大小,根元素大小都小于右子树元素大小,且子树都是二叉查找树) 所以我们需要一些非常巧妙的旋转操作 (ratate)来优化这棵树(并让他改名叫Splay) (图片顺序全反了2333) 1.节点 x 的父节点 y 是根节点.这时,如果 x 是 y 的左孩子,我们进行一次 Zig (右旋)操…
题目: 洛谷也能评测....还有我wa了10多次的记录233 题解: 不要想得太复杂,搞一个全局变量记录一下工资的改变量Delta,这样可以等询问的时候就输出val+Delta,然后插入的时候插入x-Delta 不要想会不会有员工工资一样,直接插入就好,这样省不少代码量. 对于降工资操作,插入一个min-Delta节点,ans+=左子树大小,右儿子作为新的根节点 直接走的员工不要算ans #include<cstdio> #include<algorithm> #include&l…
大二上的时候.写过一个AVL的操作演示,今天一看Splay.发现和AVL事实上一样,加上线段树的基础,懒惰标记什么都知道.学起来轻松很多哦 我參考的模板来自这里  http://blog.csdn.net/u013480600/article/list/2 里面有大量的ch[r][0] ch[r][1]等 我建议用宏定义代替,写的时候方括号少打了非常多,等做的题多得时候,我再把自己使用的模板发来 #include <cstdio> #include <cstring> #inclu…
题意:1表示插入客户K,他的优先级是P(相当于大小),2表示输出当前优先级最高的客户(即找出最大值),并且删除.3同理输出最低级的. 这题可以用splay treap AVL SBT -- (可是我并不会) 这里set水过.. #include <set> #include <cstdio> using namespace std; set<pair<int,int> >s; set<pair<int,int> >::iterator…
题意  模拟银行的排队系统  有三种操作  1-加入优先级为p 编号为k的人到队列  2-服务当前优先级最大的   3-服务当前优先级最小的  0-退出系统 能够用stl中的map   由于map本身就依据key的值排了序   相应2.3  我们仅仅须要输出最大或最小即可了并从map中删除该键值 #include<cstdio> #include<map> using namespace std; map<int, int> a; int main() { map<…
这是利用treap写的二叉排序树,只要理解其中旋转能够改变树的左右子树平衡度,即高度之差,差不多就能掌握treap树的要领了. 相对于其他高级BST,treap树实现应该算最简单了,利用的是随机树产生的理论的二叉排序树时间复杂度为O(nlgn)来实现,具体证明 算法导论 中有. 推荐NOCOW中的讲解,关于二叉排序树相当完整! treap动画展示:http://www.ibr.cs.tu-bs.de/courses/ss98/audii/applets/BST/Treap-Example.htm…
第三次做此题.. 不解释啦. 不过变成用SBT来做啦! SBT好处在于能够保证树的高度为lgn,真真正正的平衡二叉树. 因此删除,插入操作与普通二叉树几乎相同. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cstdlib> #include <cmath> #include <utility>…
Double Queue The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by IBM Romania, and using modern information technologies. As usual, each client of the bank…
Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by IBM Romania, and using modern information technologies. As usual, each client of the bank i…
#include<iostream> #include<cstring> #include<algorithm> using namespace std; ; int p[N]; struct edge{ int a; int b; int w; }e[N*N]; int map[N][N],flag[N][N],num,n; bool cmp(edge a,edge b) { return a.w<b.w; } int find(int x) { if(p[x]…
#include<iostream> #include<algorithm> using namespace std; const int N=1e5; struct edge{ int a,b,w; }e[N]; bool cmp(edge a,edge b) { return a.w<b.w; } int p[N]; int find(int x) { if(p[x]!=x) p[x]=find(p[x]); return p[x]; } int main() { int…
Treap树 核心是 利用随机数的二叉排序树的各种操作复杂度平均为O(lgn) Treap模板: #include <cstdio> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <cstdlib> #include <cmath> #include <utility> #include…
Treap树 核心是 利用随机数的二叉排序树的各种操作复杂度平均为O(lgn) Treap模板: #include <cstdio> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <cstdlib> #include <cmath> #include <utility> #include…
Treap树 核心是 利用随机数的二叉排序树的各种操作复杂度平均为O(lgn) Treap模板: #include <cstdio> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <cstdlib> #include <cmath> #include <utility> #include…
Splay 参考:https://tiger0132.blog.luogu.org/slay-notes 普通模板: ; ], val[N], cnt[N], fa[N], sz[N], lazy[N], ncnt = , rt = ; int n, m; inline int ck(int x) { ] == x; } inline void push_up(int x) { sz[x] = sz[ch[x][]] + sz[ch[x][]] + cnt[x]; } ///区间反转 inlin…
平衡树初阶——AVL平衡二叉查找树 一.什么是二叉树 1. 什么是树. 计算机科学里面的树本质是一个树状图.树首先是一个有向无环图,由根节点指向子结点.但是不严格的说,我们也研究无向树.所谓无向树就是将有向树的所有边看成无向边形成的树状图.树是一种递归的数据结构,所以我们研究树也是按照递归的方式去研究的. 2.什么是二叉树. 我们给出二叉树的递归定义如下: (1)空树是一个二叉树. (2)单个节点是一个二叉树. (3)如果一棵树中,以它的左右子节点为根形成的子树都是二叉树,那么这棵树本身也是二叉…