股票价格

时间限制: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. java的Result类

    import org.apache.commons.lang.StringUtils; import java.io.Serializable;import java.util.HashMap;imp ...

  2. Fiddler关闭自动更新

    1,fiddler 启动时老弹出要更新,但不想更新,可以这样设置 Tools-Optons->General 把第一个√去掉

  3. mysql添加federated引擎实现dblink远程表访问

    查看mysql数据库federated引擎是否开启. show engines; 若没有开启federated则在mysql配置文件my.cnf中mysqld中添加federated. 在远程数据库中 ...

  4. Cisco设备开启telnet登录

    思科设备怎么开启telnet登录 configuration line vty 0 4SW1(config-line)#transp input telne

  5. scrapy爬虫系列之五--CrawlSpider的使用

    功能点:CrawlSpider的基本使用 爬取网站:保监会 主要代码: cf.py # -*- coding: utf-8 -*- import scrapy from scrapy.linkextr ...

  6. Grafana+Prometheus监控

    添加模板一定要看说明以及依赖 监控redis https://blog.52itstyle.com/archives/2049/ http://www.cnblogs.com/sfnz/p/65669 ...

  7. React Native知识

    http://www.cnblogs.com/wujy/tag/React%20Native/    React Native知识12-与原生交互 React Native知识11-Props(属性) ...

  8. capistranorb

    远程服务器自动部署工具 https://capistranorb.com/

  9. CodeForces - 366C Dima and Salad (01背包)

    题意:n件东西,有属性a和属性b.要选取若干件东西,使得\(\frac{\sum a_j}{\sum b_j} = k\).在这个条件下,问\(\sum a_j\)最大是多少. 分析:可以将其转化为0 ...

  10. CTR预估中的贝叶斯平滑方法(一)原理及实验介绍

    1. 背景介绍 广告形式: 互联网广告可以分为以下三种: 1)展示广告(display ad) 2)搜索广告(sponsored search ad) 3)上下文广告(contextual ad)   ...