HDU3487 Play With Chains(Splay)】的更多相关文章

很裸的Splay,抄一下CLJ的模板当作复习,debug了一个下午,收获是终于搞懂了以前看这个模板里不懂的内容.以前用这个模板的时候没有看懂为什么get函数返回的前缀要加个引用,经过一下午的debug终于明白,如果加了引用的时候是会被修改到的,删除实际上就是将root->ch[1]->ch[0]置为null,但由于我们还要把这一段插回去,所以get的时候的t前面没有加引用,否则一旦置为null的话 t也会变为null.还有就是这次是第一次用这个模板进行插入,本题倒腾了很久就是在这个插入上,没有…
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) Total Submission(s): 5426    Accepted Submission(s): 2185 Problem Description YaoYao is fond of playing his chains. He has a chain containing n diamon…
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…
HDU_3487 题意:给出n和q,n代表1-n的序列,接下来q有两种操作,Cut a b c:表示把区间[a,b]截掉然后放在第c个数的后面,Flip a b 表示把区间[a,b]反转,经过一系列的q操作,最后输出操作后的序列: 分析:首先建立初始化的树结构之前,先给n设置个极限范围0和n+1,防止特殊情况下越界,如果反转[a,b],则先把第a-1个数放在根节点,把b+1结点的数放在根节点的右儿子下面,此时根节点的右儿子的左儿子为根的子树就是[a,b]区间,然后把反转标记传递给该子树的根节点,…
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…
Play with Chain Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2783    Accepted Submission(s): 1141 Problem Description YaoYao is fond of playing his chains. He has a chain containing n diamond…