
Splay Tree
九野的博客
这个作者很懒,什么都没留下…
展开
-
splay模版
#include #include #include using std::queue;const int N = 100010;struct node { node *c[2],*fa; int val; int sz; int belong; void setc(int d,node *s) { c[d原创 2013-12-15 19:35:25 · 1641 阅读 · 0 评论 -
CSU 1555 Inversion Sequence 给出逆序数求排列 splay
题目链接:点击打开链接题意:给出逆序数的值,求原序列(一个1-N的排列)1, 2, 0, 1, 0 表示1的逆序数是1,2的逆序数是2,3的逆序数是0···思路:从最后一个数开始插,每次插到当前序列的第a[i]个数。。splay模拟== 这个方法比较直(wu)观(nao),别的方法并没有想出来。。#include #includ原创 2015-04-05 22:14:28 · 1214 阅读 · 0 评论 -
HDU 3564 Another LIS splay(水
题意:给定一个空序列插入n个数(依次插入 1、2、3、4··n)下面n个数表示i插在哪个位置。每插入一个数后输出这个序列的lis然后。。。因为每次插入的数都是当前序列最大的数所以不会影响后面的数的dp值那么这个位置的dp值就是插入位置的前面最大dp值+1然后输出这个序列最大的dp值。==思路:splay。。。Q:为何这题需要用splay,不是简单原创 2014-10-23 12:02:10 · 1403 阅读 · 0 评论 -
Codeforces 38G Queue 伸展树
题目链接:点击打开链接题意:给定n个人来排队每个人有2个参数,身份优先级和脸皮厚度 ==来的那个人会排到队尾如果这个人的优先级比他前面那个人的优先级大就会和前面那个人交换位置。交换一次脸皮厚度减1, 一直交换到队头或者脸皮厚度为0交换完成后下一个人才会到来。问:队伍最后的情况(从队头到队尾依次输出每个人的编号)思路:splay维护子树的最小值。原创 2014-08-18 00:13:06 · 2073 阅读 · 0 评论 -
[NOI 2005] 维护数列 splay
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1500写的比较小心,还好没有经历虐心的wa。。数据结构的经典神题。。敲完才发现搞了250行。。思路还是很简单的,和线段树的求最大子段和一样,左连续右连续什么的,,对于区间操作都把这个区间转到根的右子树的左子树下。。1、这题需要搞个内存池,开始t原创 2014-05-30 14:03:55 · 1757 阅读 · 1 评论 -
SPOJ 4487. Can you answer these queries VI splay
题目链接:点击打开链接题意比较明显,不赘述。删除时可以把i-1转到根,把i+1转到根下则i点就在 根右子树 的左子树,且只有i这一个 点#include#include#include#includeusing namespace std;#define N 300500#define inf 10000000#define L(x) tree[x].ch[0]#d原创 2014-05-11 10:34:11 · 1957 阅读 · 0 评论 -
UVa 11922 Permutation Transformer splay 把序列翻转后放到结尾
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18902题意:给定原始序列 1-n ,m个操作,每次把区间[u,v]的数 翻转后放到序列结尾,最后中序遍历输出序列第一发手打splay#include #include #include #include using namespace std;原创 2014-03-25 14:48:03 · 1703 阅读 · 0 评论 -
HDU 1890 Robotic Sort 单点查找区间翻转 Splay裸题
题意:给定n长的序列找到其中靠右的最大值#include#include#include#include#include#includeusing namespace std;#define L(x) tree[x].ch[0]#define R(x) tree[x].ch[1]#define Father(x) tree[x].fa#defi原创 2014-05-05 22:00:31 · 1601 阅读 · 0 评论 -
POJ 3468 区间查询区间修改 伸展树
题意: n个数,有两种操作,一种是查询区间和,另一种是在区间上每一个数加上v。 把bake爷的指针版改造成了结构体版。。 #include#include#include#include#includeusing namespace std;#define ll long long#define N 100105#define inf 100原创 2014-03-07 14:04:27 · 1613 阅读 · 0 评论 -
poj3468 A Simple Problem with Integers 指针版splay
题目链接:poj 3468#include <iostream>#include <fstream>#include <string>#include <time.h>#include <vector>#include <map>#include <queue>#include <algorithm>#include <cstring>#include <cmath>#inclu原创 2015-07-03 17:05:06 · 1048 阅读 · 0 评论