hihocode 股票价格 优先队列+map
股票价格
描述
小Hi最近在分析一支股票的价格走势,他需要一个程序来辅助分析。这个程序会接收3种消息(指令):
价格信息,格式是P timestamp price:表示这支股票在 timestamp 时刻价格是 price。
删除价格指令,格式是R timestamp:随着时间推移,小Hi会积累越来越多的价格数据。一些老旧的数据会变得不重要。这个指定会删除 timestamp以前(包括 timestamp 时刻)的价格数据。
价格查询指令,格式是Q:小Hi希望程序返回这只股票最高、最低和最近的价格。注意已经被删除的价格不应该被统计。
给定一个包含以上3种信息(指令)的序列,你能否帮助小Hi完成这个程序呢?
输入
第1行包含一个整数 N (1 ≤ N ≤ 500000),表示消息(指令)序列的长度。
第2 - N+1行,每行包含一条消息或指令。
输入保证价格信息是按照 timestamp 升序排列的,并且出现的 timestamp 和价格小于100000000。
输出
对于输入中每一条价格查询指令,输出当时最高、最低和最近的价格。
- 样例输入
-
10
P 1 77
P 2 73
P 5 70
P 7 74
Q
R 4
Q
P 8 78
R 5
Q - 样例输出
-
77 70 74
74 70 74
78 74 78
思路:利用map存答案,优先队列进行操作;#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define inf 1e18
struct is
{
int num;
int pos;
friend bool operator <(is a,is b)
{
return a.pos>b.pos;
}
};
char a[];
priority_queue<is>q;
map<int,int>m;
int main()
{
int x,y,z,i,t;
int st=,en=,pre;
scanf("%d",&x);
while(x--)
{
scanf("%s",a);
if(a[]=='P')
{
is gg;
scanf("%d%d",&gg.pos,&gg.num);
pre=gg.num;
q.push(gg);
m[gg.num]++;
}
else if(a[]=='R')
{
scanf("%d",&z);
while(!q.empty())
{
if(q.top().pos<=z)
{
int v=q.top().num;
m[v]--;
if(m[v]==)
m.erase(v);
q.pop();
}
else
break;
}
}
else
{
int ansmax=(--m.end())->first;
int ansmin=m.lower_bound(st)->first;
printf("%d %d %d\n",ansmax,ansmin,pre);
}
}
return ;
}
hihocode 股票价格 优先队列+map的更多相关文章
- Northwestern European Regional Contest 2016 NWERC ,F题Free Weights(优先队列+Map标记+模拟)
传送门: Vjudge:https://vjudge.net/problem/Gym-101170F CF: http://codeforces.com/gym/101170 The city of ...
- HDU 6015 Skip the Class 优先队列 map的使用
Skip the Class Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...
- A - Enterprising Escape 【BFS+优先队列+map】
The Enterprise is surrounded by Klingons! Find the escape route that has the quickest exit time, and ...
- Generating Sets 贪心
H - Generating Sets Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- codeforces 15D . Map 优先队列
题目链接 题目意思很简单nm的矩阵里, 选若干个ab的小矩阵, 定义每个矩阵的值为这个矩阵里的所有数的和-最小值*数的个数. 选小矩阵时, 优先选值最小的,然后次小的.. 知道不能选位置. 输出所有矩 ...
- ACM学习历程—HDU 2112 HDU Today(map && spfa && 优先队列)
Description 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候,XHD夫妇也退居了二线 ...
- C/C++解题常用STL大礼包 含vector,map,set,queue(含优先队列) ,stack的常用用法
每次忘记都去查,真难啊 /* C/C++解题常用STL大礼包 含vector,map,set,queue(含优先队列) ,stack的常用用法 */ /* vector常用用法 */ //头文件 #i ...
- Gym 100952F&&2015 HIAST Collegiate Programming Contest F. Contestants Ranking【BFS+STL乱搞(map+vector)+优先队列】
F. Contestants Ranking time limit per test:1 second memory limit per test:24 megabytes input:standar ...
- NBOJv2——Problem 1037: Wormhole(map邻接表+优先队列SPFA)
Problem 1037: Wormhole Time Limits: 5000 MS Memory Limits: 200000 KB 64-bit interger IO format: ...
随机推荐
- 华硕蓝光刻录机在MAC系统里能用吗?
答案是刻录功能不能用(没有驱动),但可以当外置光驱用.需要注意的是单单把刻录机插到MAC电脑上是没有反应的,放入光盘后Finder里会出现一个可移动设备.
- 04.ActiveMQ与Spring JMS整合
SpringJMS使用参考:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jms.html ...
- html锚点的作用和js选项卡锚点跳转的使用
location是javascript里边管理地址栏的内置对象,比如location.href就管理页面的url,用location.href=url就可以直接将页面重定向url.而location. ...
- Django - 常用配置
一.logging配置 Django项目常用的logging配置 settings.py LOGGING = { 'version': 1, 'disable_existing_loggers': F ...
- 运行mlflow命令报错 The 'nose' distribution was not found and is required by nose-exclude
安装好mlflow之后命令行运行: mlflow 得到报错: 解决: sudo pip3 install nose
- WPF自定义代码启动应用程序启动方式
删除app.xaml 添加App.cs类 第一种方式: class App { [STAThread] static void Main() { ...
- MySQL 通用查询日志和慢查询日志分析
MySQL中的日志包括:错误日志.二进制日志.通用查询日志.慢查询日志等等.这里主要介绍下比较常用的两个功能:通用查询日志和慢查询日志. 1)通用查询日志:记录建立的客户端连接和执行的语句.2)慢查询 ...
- centos linux系统日常管理复习 CPU物理数逻辑核数,iftop ,iotop ,sar ,ps,netstat ,一网卡多IP,mii-tool 连接,ethtool速率,一个网卡配置多个IP,mii-tool 连接,ethtool速率 ,crontab备份, 第十八节课
centos linux系统日常管理复习 物理CPU和每颗CPU的逻辑核数,uptime ,w,vmstat,iftop ,iotop ,sar ,ps,netstat ,一个网卡配置多个IP,mii ...
- Mysql5.6主从复制
搭建(192.168.1.10 -> 192.168.1.20) 1 master 上执行 阻塞 DMLflush tables with read lock; 记录 File 和 Positi ...
- WMS学习笔记:1.尝试加载WMS
1.首先找一个可用的WMS栅格地图服务:http://demo.cubewerx.com/demo/cubeserv/cubeserv.cgi 获取GetCapabilities: http://de ...