优先队列 || POJ 1442 Black Box
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
#define SZ 30005
#define INF 1e9+10
int a[SZ];
priority_queue<int> q1, q2;
int main()
{
int n, m, b;
scanf("%d %d", &n, &m);
for(int i = ; i < n; i++)
scanf("%d", &a[i]);
int j = ;
for(int i = ; i <= m; i++)
{
scanf("%d", &b);//在第b次插入后输出第i小的元素,保证q1中始终有i-1个元素
while(j < b)
{
if(q1.empty() || a[j] > q1.top())//把empty的判断放在前面,否则访问top会RE
{
q2.push(-a[j]);
}
else
{
int tmp = q1.top();
q1.pop();
q1.push(a[j]);
q2.push(-tmp);
}
j++;
}
int tmp = -q2.top(); q2.pop();
printf("%d\n", tmp);
q1.push(tmp);
}
return ;
}
优先队列 || POJ 1442 Black Box的更多相关文章
- POJ 1442 Black Box treap求区间第k大
题目来源:POJ 1442 Black Box 题意:输入xi 输出前xi个数的第i大的数 思路:试了下自己的treap模版 #include <cstdio> #include < ...
- POJ 1442 Black Box(优先队列)
题目地址:POJ 1442 这题是用了两个优先队列,当中一个是较大优先.还有一个是较小优先. 让较大优先的队列保持k个.每次输出较大优先队列的队头. 每次取出一个数之后,都要先进行推断,假设这个数比較 ...
- poj 1442 Black Box(堆 优先队列)
题目:http://poj.org/problem?id=1442 题意:n,m,分别是a数组,u数组的个数,u[i]w为几,就加到a几,然后输出第i 小的 刚开始用了一个小顶堆,超时,后来看了看别人 ...
- [ACM] POJ 1442 Black Box (堆,优先队列)
Black Box Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7099 Accepted: 2888 Descrip ...
- poj 1442 Black Box(优先队列&Treap)
题目链接:http://poj.org/problem?id=1442 思路分析: <1>维护一个最小堆与最大堆,最大堆中存储最小的K个数,其余存储在最小堆中; <2>使用Tr ...
- POJ 1442 Black Box -优先队列
优先队列..刚开始用蠢办法,经过一个vector容器中转,这么一来一回这么多趟,肯定超时啊. 超时代码如下: #include <iostream> #include <cstdio ...
- POJ 1442 Black Box 堆
题目: http://poj.org/problem?id=1442 开始用二叉排序树写的,TLE了,改成优先队列,过了.. 两个版本都贴一下吧,赚稿费.. #include <stdio.h& ...
- POJ 1442 Black Box
第k大数维护,我推荐Treap..谁用谁知道.... Black Box Time ...
- 数据结构(堆):POJ 1442 Black Box
Black Box Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10658 Accepted: 4390 Descri ...
随机推荐
- bzoj2676
二分概率+矩乘+dp 也是二分概率,然后dp[i][j][k]表示当前到了i,有j条命,下一次的收益是k,然后矩乘转移,但是我自己的似乎wa了,抄了liu_runda的才行,具体不知道为什么 注释的是 ...
- (转)ORA-01245错误 (2013-04-13 18:37:01)
转自:http://blog.sina.com.cn/s/blog_56359cc90101crx2.html 数据库rman restore database 之后,执行recover databa ...
- bzoj 1478: Sgu282 Isomorphism && 1815: [Shoi2006]color 有色图【dfs+polya定理】
参考 https://wenku.baidu.com/view/fee9e9b9bceb19e8b8f6ba7a.html?from=search### 的最后一道例题 首先无向完全图是个若干点的置换 ...
- LuoguP2657 [SCOI2009]windy数 【数位dp】By cellur925
题目传送门 题目大意:在A和B之间,包括A和B,总共有多少个不含前导零且相邻两个数字之差至少为2的正整数? 显然是数位dp啦=w=. 显然与上一位有关,我们$dfs$的时候就要记录$pre$.因为这是 ...
- 安装elasticsearch-rtf出错
出错信息: elasticsearch-rtf Caused by: java.lang.IllegalStateException: No match found 解决方法: 参考:https: ...
- java实训 :异常(try-catch执行顺序与自定义异常)
关键字: try:执行可能产生异常的代码 catch:捕获异常 finally:无论是否发生异常代码总能执行 throws:声明方法可能要抛出的各种异常 throw:手动抛出自定义异常 用 try-c ...
- Redis的高级特性哨兵
一.哨兵介绍 Redis Sentinel,即Redis哨兵,在Redis 2.8版本开始引入.哨兵的核心功能是主节点的自动故障转移.下面是Redis官方文档对于哨兵功能的描述: 监控(Monitor ...
- MySql | 常用操作总结
创建数据库: CREATE DATABASE 数据库名; 删除数据库名: drop database <数据库名>; 选择数据库: use 数据库名; 创建数据表: CREATE TABL ...
- Jquery | 基础 | 慕课网 | (*选择器)
原生JS var elements1 = document.getElementsByTagName('*'); JQ var elements2 = $("*"); <!D ...
- AtCoder Grand Contest 012 A
A - AtCoder Group Contest Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statem ...