QOJ.ac

QOJ

時間限制: 2.0 s 記憶體限制: 2048 MB 總分: 100

#16062. 股票价格

统计

在本题中,我们将处理股票价格的计算。你需要了解以下关于股票价格的概念:

  • 卖一价(ask price)是某人愿意卖出一股股票的最低价格。
  • 买一价(bid price)是某人愿意买入一股股票的最高价格。
  • 最新成交价(stock price)是最近一次交易达成的价格。

每当买一价大于或等于卖一价时,交易就会达成。出价为买一价的买单会与要价为卖一价的卖单进行匹配,股票将以卖一价的价格进行交易,直到卖单或买单(或两者)被完全填满(即买方不再需要更多股票,或卖方不再想卖出更多股票)。你会收到一系列订单(买单或卖单),你需要在处理完每个订单后,计算当前的卖一价、买一价和最新成交价。

输入格式

第一行包含一个正整数:测试用例的数量,最多为 $100$。对于每个测试用例:

  • 第一行包含一个整数 $n$ ($1 \le n \le 1\,000$):订单的数量。
  • 接下来的 $n$ 行,每行格式为 order_type x shares at y,其中 order_typebuysell,$x$ ($1 \le x \le 1\,000$) 是某人想要买入或卖出的股票股数,$y$ ($1 \le y \le 1\,000$) 是期望的价格。

输出格式

对于每个测试用例:

  • 输出 $n$ 行,每行格式为 $a_i$ $b_i$ $s_i$,其中 $a_i$、$b_i$ 和 $s_i$ 分别代表在处理完第 $i$ 个订单且所有可能的交易都发生后,当前的卖一价、买一价和最新成交价。如果某个价格未定义,则输出 - 代替该价格。

样例

输入样例 1

2
6
buy 10 shares at 100
sell 1 shares at 120
sell 20 shares at 110
buy 30 shares at 110
sell 10 shares at 99
buy 1 shares at 120
6
sell 10 shares at 100
buy 1 shares at 80
buy 20 shares at 90
sell 30 shares at 90
buy 10 shares at 101
sell 1 shares at 80

输出样例 1

- 100 -
120 100 -
110 100 -
120 110 110
120 100 99
- 100 120
100 - -
100 80 -
100 90 -
90 80 90
100 80 90
100 - 80

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.