poj1442 Black Box
The Black Case 好啊!
首先,读题很艰难...
读完题,发现是求第k小的数,那么我们用splay水过对顶堆水过即可。
#include <cstdio>
#include <queue>
const int N = ;
// poj 1442 黑箱
struct DeHeap {
std::priority_queue<int> DOWN;
std::priority_queue<int, std::vector<int>, std::greater<int> > UP;
inline void clear() {
while(!UP.empty()) {
UP.pop();
}
while(!DOWN.empty()) {
DOWN.pop();
}
return;
}
inline void insert(int x) {
if(DOWN.empty()) {
UP.push(x);
}
else if(x >= DOWN.top()) {
UP.push(x);
}
else {
DOWN.push(x);
UP.push(DOWN.top());
DOWN.pop();
}
return;
}
inline int get() {
int x = UP.top();
DOWN.push(x);
UP.pop();
return x;
}
}dh; int add[N]; int main() {
int n, m, x, T = ;
while(T--) {
dh.clear();
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) {
scanf("%d", &add[i]);
}
int k = ;
for(int i = ; i <= m; i++) {
scanf("%d", &x);
while(k <= x) {
dh.insert(add[k]);
k++;
}
printf("%d\n", dh.get());
}
printf("\n");
}
return ;
}
AC代码
poj1442 Black Box的更多相关文章
- poj-1442 Black Box(Treap)
题目链接: Black Box 题意: 给一个序列,m个询问,每个询问是求前x个数中的第i小是多少; 思路: Treap的入门题目;Treap能实现STL的set实现不了的功能,如名次树(rank t ...
- POJ-1442 Black Box,treap名次树!
Black Box 唉,一天几乎就只做了这道题,成就感颇低啊! 题意:有一系列插入查找操作,插入每次 ...
- POJ1442 Black Box 堆
用大根堆和小根堆分别存放前$i-1$大的元素前$k-i$小的元素. 将当前序列的元素压入最小堆,如果最小堆的最小数大于最大堆的最大数则进行交换,保证最大堆中的所有数小于最小堆. 因为$i$值每进行一次 ...
- 初识Treap
Treap,简单的来说就是Tree+Heap,是一颗平衡树,每个节点有两个信息:1.key:当前节点的关键字 :2.fix:当前节点优先级.key满足二叉排序数的性质,即左儿子都比当前节点小,右儿子都 ...
- 【POJ1442】【Treap】Black Box
Description Our Black Box represents a primitive database. It can save an integer array and has a sp ...
- Black Box POJ1442
Description Our Black Box represents a primitive database. It can save an integer array and has a sp ...
- 【poj1442】Black Box
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10890 Accepted: 4446 Description Our ...
- POJ1442:Black Box
浅谈堆:https://www.cnblogs.com/AKMer/p/10284629.html 题目传送门:http://poj.org/problem?id=1442 用对顶堆维护第\(k\)小 ...
- A - Black Box 优先队列
来源poj1442 Our Black Box represents a primitive database. It can save an integer array and has a spec ...
随机推荐
- ubuntu18.04 安装 php7.2
sudo apt-get install software-properties-common python-software-properties sudo add-apt-repository p ...
- cmd & tree & bash
cmd & tree & bash bug E: Unable to locate package tree solution # 1. update $ sudo apt-get u ...
- python学习 第二天
一.变量 1.变量名: 数字,字母,下划线 alex1=123 sb=“alex” a_lex=“sb” 不能以数字开头 lalex 变量名不是python内部的关键字 {‘and’,'as','as ...
- jQ append 添加html 及字符串拼接
如图,我要拼接这样一段html: 点击下边添加按钮,不断添加这段Html html: <div class="x_addtable"> <div class=&q ...
- MyBatis基础:MyBatis动态SQL(3)
1. 概述 MyBatis中动态SQL包括元素: 元素 作用 备注 if 判断语句 单条件分支判断 choose(when.otherwise) 相当于Java中的case when语句 多条件分支判 ...
- 1.Java简介
第一章 Java简介 开始上传一些自己画的思维导图 画的基本上是根据菜鸟教程Java的对应的图 会有一系列的图陆续放出来,不过博客上只有截图,具体的带注释的具体的图后续会放在git上,更新会加上git ...
- LOADING Redis is loading the dataset in memory Redis javaAPI实例
今天在实现Redis客户端API操作Jedis的八种调用方式详解中,遇到了LOADING Redis is loading the dataset in memory错误,经过多番查找资料,找到了解决 ...
- css的特性
一.继承性: 继承是一种规则,它允许样式不仅应用于某个特定html标签元素,而且应用于其后代. /* 不具有继承性的css样式: */p{border:1px solid red;} 二.特殊性(优先 ...
- 洛谷 P3951 小凯的疑惑
题目链接 一开始看到这题,我的内心是拒绝的. 以为是同余类bfs,一看数据1e9,发现只能允许O(1)的算法,数学还不太好,做不出来,其实应该打表找规律. 看到网上的题解,如果两个都必须拿,结果一定是 ...
- Qt QLineEdit
//lineEdit显示文字 QLineEdit *lineEdit = new QLineEdit(widget); lineEdit->setObjectName(QString()); l ...