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 ...
随机推荐
- Keras和tensorflow的区别
参考: https://blog.csdn.net/zhangbaoanhadoop/article/details/82111056
- python之路--FTP 上传视频示例
# 服务端 import json import socket import struct server = socket.socket() server.bind(('127.0.0.1',8001 ...
- Golang的日志处理
整个看了一圈下来,感觉Golang的日志包在管理多线程安全的情况下,提供了最小粒度的工具.并没有提供什么复杂的过滤器之类的生成. 实现了一个demo来记录一下日志分类日志打印等实现: package ...
- centos7系统管理和运维实战——运维必备的网络管理技能(1)
运维必备的网络管理技能 一.网络管理协议: 1.简单的两个概念: DHCP(动态主机配置协议):如果网络结构要更改,需要从新初始化网络参数,手机用动态主机配置协议可以避免这个问题.客户端可以从D ...
- 原型链上的call方法集合
1. Object.prototype.toString.call(value) // 返回数据的类型 // "[object Object]" 等 2. Array.protot ...
- html5 表單屬性
新的 form 属性: autocomplete novalidate 新的 input 属性: autocomplete autofocus form form overrides (formact ...
- 三、oneinstack
一.介绍 oneinstack https://www.cnblogs.com/lxwphp/p/9231554.html
- vue-cli: 渲染过程理解(vue create demo01方式创建)
1.根目录配置 vue.config.js, 设置入口文件: index.js module.exports = { pages:{ index: { entry: 'src/pages/home/i ...
- MySQL 优化小技巧
碎片整理: mysql数据一开始是在磁盘上顺序存放的,如果数据表有频繁的update改动,那么数据就会形成很多碎片,拖慢速度和不利于索引: 优化碎片有两种方式: alter table user en ...
- Web API 2 使用SSL
在Server上启用SSL 稍后我会想在IIS 7 上配置SSL,现在先往下看. 本地测试,您可以启用SSL的IIS Express Visual Studio.在属性窗口中,启用SSL设置为True ...