HDU3487 Play With Chain [Splay]】的更多相关文章

Play with Chain Problem Description YaoYao is fond of playing his chains. He has a chain containing n diamonds on it. Diamonds are numbered from 1 to n.At first, the diamonds on the chain is a sequence: 1, 2, 3, …, n.He will perform two types of oper…
题目传送门 题目描述 Problem Description YaoYao is fond of playing his chains. He has a chain containing n diamonds on it. Diamonds are numbered from 1 to n.At first, the diamonds on the chain is a sequence: 1, 2, 3, …, n.He will perform two types of operation…
HDU3487 splay最核心的功能是将平衡树中的节点旋转到他的某个祖先的位置,并且维持平衡树的性质不变. 两个操作(数组实现) cut l,r, c把[l,r]剪下来放到剩下序列中第c个后面的位置. flip l r 把[l,r]翻转(lazy标记,每次交换左右节点) cut思路:把l-1旋到根,r+1旋到根的右节点,取下这一段:在剩下的序列中找到c,c+1的位置,把c旋到根,c+1旋到右节点,插入. 由平衡树性质易证得是对的(中序遍历恒定) flip思路:把l-1旋到根,r+1旋到右节点,…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3487 对于一个数列有两种操作:1.CUT a b c,先取出a-b区间的数,然后把它们放在取出后的第c个数后面.2.FLIP a b,把区间a-b的数反转.对于第一个操作,进行两次区间移动,第a-1个数Splay到根节点,b+1个数Splay到root的右儿子,ch[ch[root][1]][0]则表示那个区间,然后把它们除掉,然后在移动区间,把第c个数Splay到root,第c+1个数Splay到…
Play with Chain Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) [Problem Description] YaoYao is fond of playing his chains. He has a chain containing n diamonds on it. Diamonds are numbered from 1 to n. At first, t…
题目大意:给出1到n的有序数列,现在有两个操作: 1.CUT a b c 把第a到第b个数剪切下来,放到剩下的第c个数的后边. 2.FLIP a b  把第a到第b个数反转. 经过总共m次操作后,求现在的数列. n,m<300000 分析:典型的splay题.包含的操作即:查找第k大,剪切,插入,反转等操作. 维护size,rev(反转标记)即可. 通过size可以找到第k大,通过rev做懒标记,可以进行反转. 具体说就是,比如要剪切CUT a,b,c,以先把第a-1个节点splay到根的位置,…
很裸的Splay,抄一下CLJ的模板当作复习,debug了一个下午,收获是终于搞懂了以前看这个模板里不懂的内容.以前用这个模板的时候没有看懂为什么get函数返回的前缀要加个引用,经过一下午的debug终于明白,如果加了引用的时候是会被修改到的,删除实际上就是将root->ch[1]->ch[0]置为null,但由于我们还要把这一段插回去,所以get的时候的t前面没有加引用,否则一旦置为null的话 t也会变为null.还有就是这次是第一次用这个模板进行插入,本题倒腾了很久就是在这个插入上,没有…
题意 给定$n$个数序列,每次两个操作,将区间$[L,R]$拼接到去掉区间后的第$c$个数后,或者翻转$[L,R]$ Splay区间操作模板,对于区间提取操作,将$L-1$ Splay到根,再将$R+1$ Splay到根节点的右儿子,那么根节点右儿子的左儿子就对应区间$[L,R]$,对于反转操作,通过懒操作下放 代码 #include <bits/stdc++.h> #define inf 0x7f7f7f7f using namespace std; const int N = 500005…
链接 简单的两种操作,一种删除某段区间,加在第I个点的后面,另一个是翻转区间.都是splay的简单操作. 悲剧一:pushdown时候忘记让lz=0 悲剧二:删除区间,加在某点之后的时候忘记修改其父亲节点. #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> #include<vector> #inc…
Problem Description YaoYao is fond of playing his chains. He has a chain containing n diamonds on it. Diamonds are numbered from 1 to n.At first, the diamonds on the chain is a sequence: 1, 2, 3, …, n.He will perform two types of operations:CUT a b c…