股票价格

时间限制:20000ms
单点时限:2000ms
内存限制:256MB

描述

小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的更多相关文章

  1. 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 ...

  2. HDU 6015 Skip the Class 优先队列 map的使用

    Skip the Class Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...

  3. A - Enterprising Escape 【BFS+优先队列+map】

    The Enterprise is surrounded by Klingons! Find the escape route that has the quickest exit time, and ...

  4. Generating Sets 贪心

    H - Generating Sets Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  5. codeforces 15D . Map 优先队列

    题目链接 题目意思很简单nm的矩阵里, 选若干个ab的小矩阵, 定义每个矩阵的值为这个矩阵里的所有数的和-最小值*数的个数. 选小矩阵时, 优先选值最小的,然后次小的.. 知道不能选位置. 输出所有矩 ...

  6. ACM学习历程—HDU 2112 HDU Today(map && spfa && 优先队列)

    Description 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候,XHD夫妇也退居了二线 ...

  7. C/C++解题常用STL大礼包 含vector,map,set,queue(含优先队列) ,stack的常用用法

    每次忘记都去查,真难啊 /* C/C++解题常用STL大礼包 含vector,map,set,queue(含优先队列) ,stack的常用用法 */ /* vector常用用法 */ //头文件 #i ...

  8. 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 ...

  9. NBOJv2——Problem 1037: Wormhole(map邻接表+优先队列SPFA)

    Problem 1037: Wormhole Time Limits:  5000 MS   Memory Limits:  200000 KB 64-bit interger IO format: ...

随机推荐

  1. eclipse 安装Subversion1.82(SVN)插件

    Eclipse下SVN插件的安装,可以选择在线安装和离线安装两种方式: 2.(可选①)使用本地安装包安装插件 --填写插件名(可随意取名) --插件来源地址(①安装包,②使用网址) →Archie→选 ...

  2. redis数据持久化(快照/日志):

    1.RDB快照的配置选项: save // 900内,有1条写入,则产生快照 save // 如果300秒内有1000次写入,则产生快照 save // 如果60秒内有10000次写入,则产生快照 ( ...

  3. MVC之路由

    1.路由规则理解: 在MVC项目中,路由是一个独立的模块,需要引入System.Web.Routing ,路由的作用就是确定控制器和行为,同时确定其他的参数,然后将这些信息传递个相应的控制器和行为. ...

  4. 南京网络赛J-Sum【数论】

    A square-free integer is an integer which is indivisible by any square number except 11. For example ...

  5. c# devExpress控件 comboBoxEdit,gridControl1,labelcontrol

    一.comboBoxEdit:下拉框 属性 添加项:Properties->items 二.gridControl gridControl与Gridview的区别:前者是容器,后者为视图 2)g ...

  6. MyBatis 的真正强大在于它的映射语句 如果有一个独立且完美的数据库映射模式,所有应用程序都可以使用它

    mybatis – MyBatis 3 | Mapper XML 文件 http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html mybatis – My ...

  7. Python开发【模块】:内置模块

    内置模块 1.__import__ # import app目录下的kingadmin.py文件 for app in conf.settings.INSTALLED_APPS: __import__ ...

  8. pandas 取消读取csv时默认第一行为列名

    读取时默认第一行为列名 此时DataFrame的列名为第一行数据: 因为第一行为有效数据,故不可作为列名,要么重新起列名,要么使用默认序列列名: 取消默认第一行为列名 给 pd.read_csv() ...

  9. Mirror--镜像相关操作

    其他相关操作1. 关闭镜像--关闭镜像USE [master]GOALTER DATABASE Demo1 SET PARTNER OFFGO  2. 证服务器--移除见证服务器USE [master ...

  10. apache ab test使用 单独安装ab和htpasswd

    apache ab test使用 apache ab test使用 单独安装ab和htpasswd 转载自: http://www.cnblogs.com/super-d2/p/3831155.htm ...