HDU3487 Play with Chain SPLAY 区间分裂,区间合并,区间翻转

这道题目涉及了伸展树的分裂特点。这里注意,当我们要对伸展树做区间分裂操作的时候,我们要添加开始于结尾两个点,用于防范边界情况。输出时特殊判断即可。具体做法是在build建树之前先手动给root一个值0然后给root的右儿子一个值n+1,这样我们就形成了一个区间【0,n+1】,然后我们在将要建立的1-n这棵树放在root的右儿子的左子树上。这里一定要理解。因为以后我们对伸展树的区间操作都是这种方
摘要由CSDN通过智能技术生成

这道题目涉及了伸展树的分裂特点。

这里注意,当我们要对伸展树做区间分裂操作的时候,我们要添加开始于结尾两个点,用于防范边界情况。输出时特殊判断即可。具体做法是在build建树之前先手动给root一个值0然后给root的右儿子一个值n+1,这样我们就形成了一个区间【0,n+1】,然后我们在将要建立的1-n这棵树放在root的右儿子的左子树上。这里一定要理解。因为以后我们对伸展树的区间操作都是这种方法,假如要提取区间【a,b】那么我们就要将a-1旋转到根,b+1旋转到根的右儿子。然后很显然,右儿子的左子树就是我们所要找的区间。

CUT a,b,c  这个操作要求我们将区间[a,b]分裂出来然后添加在第c个数后面。具体取法与上面相同。这里说一下合并到c之后的方法,做法就是将C旋转到root,然后将右子树的最小值旋转到右子树的根,然后我们在将区间插入右子树的左子树。

FLIP a,b 区间翻转。

这里要注意下。我上面说的a,b都是从左往右第a或第b个数。

总结一下关键字:区间   ,root的右儿子的左子树。

我的splay。。。好长的代码量啊,,,能用treap我一定不用splay。。。。。

 

 

Play with Chain

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2429    Accepted Submission(s): 980


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: He will first cut down the chain from the ath diamond to the bth diamond. And then insert it after the cth diamond on the remaining chain.
For example, if n=8, the chain is: 1 2 3 4 5 6 7 8; We perform “CUT 3 5 4”, Then we first cut down 3 4 5, and the remaining chain would be: 1 2 6 7 8. Then we insert “3 4 5” into the chain before 5th diamond, the chain turns out to be: 1 2 6 7 3 4 5 8.

FLIP a b: We first cut down the chain from the ath diamond to the bth diamond. Then reverse the chain and put them back to the original position.
For example, if we perform “FLIP
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值