poj1442 Black Box】的更多相关文章

题目链接: Black Box 题意: 给一个序列,m个询问,每个询问是求前x个数中的第i小是多少; 思路: Treap的入门题目;Treap能实现STL的set实现不了的功能,如名次树(rank tree)rank tree 支持两种新操作,一个是找出第k小元素,一个是找出x的的rank; AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm>…
                                                  Black Box 唉,一天几乎就只做了这道题,成就感颇低啊! 题意:有一系列插入查找操作,插入每次在有序数列中插入一个数,保证插入后数列还是有序,初始数列为空,每次查询一个排名为i的数,第i次查询排名为i的数.给你两个数列,第一个是插入数的顺序,第二个是每次查询发生在插入第U(i)个数之后.具体看样例,说实话我也理解了挺久,数列1 2 6 6 表示的是第一次查询是在插入第一个数之后,第二次查询是…
The Black Case 好啊! 首先,读题很艰难... 读完题,发现是求第k小的数,那么我们用splay水过对顶堆水过即可. #include <cstdio> #include <queue> ; // poj 1442 黑箱 struct DeHeap { std::priority_queue<int> DOWN; std::priority_queue<int, std::vector<int>, std::greater<int&…
用大根堆和小根堆分别存放前$i-1$大的元素前$k-i$小的元素. 将当前序列的元素压入最小堆,如果最小堆的最小数大于最大堆的最大数则进行交换,保证最大堆中的所有数小于最小堆. 因为$i$值每进行一次自增$1$,所以每次$get$操作后将小根堆顶弹出存入大根堆. #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #in…
Treap,简单的来说就是Tree+Heap,是一颗平衡树,每个节点有两个信息:1.key:当前节点的关键字 :2.fix:当前节点优先级.key满足二叉排序数的性质,即左儿子都比当前节点小,右儿子都比当前节点大(或相等),fix是一个随机的数,满足小根堆(或大根堆)的性质,fix是为了防止Treap退化成链表的简单优化策略. 如下面的一颗Treap: Treap可以进行下面几种操作:插入,查询第k大,旋转,还有其他一些基本操作和一些高级的操作,这里暂不作介绍. 1.插入元素 Treap的关联形…
Description Our Black Box represents a primitive database. It can save an integer array and has a special i variable. At the initial moment Black Box is empty and i equals 0. This Black Box processes a sequence of commands (transactions). There are t…
Description Our Black Box represents a primitive database. It can save an integer array and has a special i variable. At the initial moment Black Box is empty and i equals 0. This Black Box processes a sequence of commands (transactions). There are t…
Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10890   Accepted: 4446 Description Our Black Box represents a primitive database. It can save an integer array and has a special i variable. At the initial moment Black Box is empty and i e…
浅谈堆:https://www.cnblogs.com/AKMer/p/10284629.html 题目传送门:http://poj.org/problem?id=1442 用对顶堆维护第\(k\)小即可.保持小根堆大小逐渐递增就行. 时间复杂度:\(O(mlogn)\) 空间复杂度:\(O(n)\) 代码如下: #include <cstdio> #include <algorithm> using namespace std; const int maxn=3e4+5; int…
来源poj1442 Our Black Box represents a primitive database. It can save an integer array and has a special i variable. At the initial moment Black Box is empty and i equals 0. This Black Box processes a sequence of commands (transactions). There are two…