优先队列 || 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 ...
随机推荐
- caffe从入门到放弃
断断续续折腾ML近一年,写点博客记录这个坑.
- hibernate -- 分页模糊查询中setParameter 和setParameterList
在分页模糊查询中碰到setParameter 和setParameterList这两个方法 setParameter 以前就只会用setParameter(int arg,String str),我用 ...
- 6-5 Haar特征2
在遍历的过程中还需要考虑到一个步长的问题.这个模板一次滑动10个像素,那么总共就需要滑动9次.再加上最开始的第0次,合计在水平方向上和竖直方向上分别都有10个这样的模板,总共也就是100个模板.要计算 ...
- innobackupex参数说明
1.备份: #常用参数 --user:该选项表示备份账号. --password:该选项表示备份的密码. --port:该选项表示备份数据库的端口. --host:该选项表示备份数据库的地址. --s ...
- 公司内网,无法使用yum在线下载,肿么办?
1 配置上网代理 编辑/etc/yum.conf,增加如下属性: proxy=你的代理地址 proxy_user=你的用户名 proxy_password=你的密码 2 配置国内163 yum源 备份 ...
- Struts+Spring+Hibernate处理Lob(Blob,Clob)
在使用struts+spring+hibernate的开发中,有些时候用户会有数据库存储文件的需求,在数据库中一般会采用Blob字段或Clob字段来存储二进制图片.流媒体或文件.现就将在实际开发中遇到 ...
- 揭开Python科学计算的面纱
春牛春杖.无限春风来海上.便与春工.染得桃红似肉红. 春幡春胜.一阵春风吹酒醒.不似天涯.卷起杨花似雪花. 标准的Python中用列表保存一组值,可以当做数组使用,但是由于其值类型任意,所以列表中保存 ...
- websocket实现单聊
server# @File: ws from flask import Flask, request, render_template from geventwebsocket.handler imp ...
- [WOJ1138]最大子序和
题目链接: WOJ1138 题目分析: 是很经典的一道题,乱搞的方法应该有不少,这里介绍O(n)的单调队列做法 首先维护一个前缀和,然后枚举每一个位置,维护一个前缀和单增的单调队列,但队列仅储存下标, ...
- iphone6,键盘收起,H5页面下面出现空白