[HDU1890]RoboticSort】的更多相关文章

Problem 每次找到最小值,然后把它和它前面的数翻转,然后找第二小数······ 然后输出这些数的下标. Solution 用splay维护,每次找到最小值,然后翻转前面区间. Notice 细节操作巨烦无比. Code #include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #…
Robotic Sort Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3913    Accepted Submission(s): 1717 Problem Description Somewhere deep in the Czech Technical University buildings, there are labora…
对于大神来说这题是水题.我搞这题花了快2天. 伸展树的优点有什么,就是树不管你怎么旋转序列是不会改变得,并且你要使区间反转,只要把第k大的点转到根结点,那么它的左子树就是要交换的区间[l,r),然后交换左右 子树就可以了(中序),根结点的位置就是i+siz[ch[root][0]],i是处理完的结点个数,siz[ch[root][0]]就是左子树(需要旋转的个数). 旋转可以用lazy思想标记,这样时间就为logn了.由于第k大的值已经处理完成,所以直接将根结点删除. 代码: #include<…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1890 题目中涉及数的反转和删除操作,需要用Splay tree来实现.首先对数列排序,得到每个数在数列中的下标x.Splay tree的每个节点标记以它为根的子树是否需要反转,用到懒惰操作,保证nlogn,在每次操作的时候Push_Down()和Push_Up.在建树的时候是数的下标为节点标号建立数,如果要询问数num[i],则把num[i]在数列中的下标旋转到根节点root,size[ch[roo…
这题的建模有点不太一样,是按结点横坐标赋予键值的 同时每次rotate和splay时都要注意下往上往下更新 /* 先建立好splay tree,将结点按num/输入顺序排序,遍历时每次将当前结点提到根节点,输出其在splay树中排第几个 然后rev左子树,最后remove */ #include<iostream> #include<cstring> #include<cstdio> using namespace std; #include<algorithm&…
Problem Description Somewhere deep in the Czech Technical University buildings, there are laboratories for examining mechanical and electrical properties of various materials. In one of yesterday's presentations, you have seen how was one of the labo…
Robotic Sort Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) [Problem Description] Somewhere deep in the Czech Technical University buildings, there are laboratories for examining mechanical and electrical properti…
Robotic Sort Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3340    Accepted Submission(s): 1423 Problem Description Somewhere deep in the Czech Technical University buildings, there are labor…
伸展树是一种强大的数据结构,由于其特性,可以很好地模拟队列的插队等操作,而线段树解决这类问题通常需要转化一下,比较伤脑筋 而用伸展树的解决方法就是先建好一颗节点数等于队列长度的树,每个队列元素在队列中的排名就是这个元素在伸展树中的结点号 那么询问 i 在队列中的排名:splay(i,0), rank=size[ch[root][0]]+1; 询问队列中第 i 个元素是什么:在伸展树中找到第i个元素,其节点号就是答案 hdu1890:有两种操作:模拟队列:把结点i移到队列最前面(删除根结点+移点操…
Robotic Sort Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1640    Accepted Submission(s): 711 Problem Description Somewhere deep in the Czech Technical University buildings, there are laborat…