QOJ.ac

QOJ

时间限制: 4.0 s 内存限制: 256 MB 总分: 100

#9383. 硬币日毁灭

统计

小 Alya 非常喜欢加密货币。去年,她甚至创造了自己的加密货币:alcoin!到目前为止,alcoin 唯一的功能就是从一个地址转移到另一个地址。在任何时刻,每个地址都包含非负数量的 alcoin,而从一个地址到另一个地址的转账会相应地改变金额。服务地址 00000000 是特殊的:从该地址发出的转账会创造新的 alcoin,而转入该地址的转账会将转移的代币从流通中移除。

几个月来,Alya 和她的朋友们一直在使用分布式 alcoin 网络进行相互结算。但 Alya 想要更多:让全世界都使用 alcoin。迈向成功的一步是引入 alcoin 到加密货币交易所,以促进 alcoin 与其他货币的买卖。

引起 Alya 注意的交易所服务要求(除其他事项外)计算并提交所提议加密货币的几个参数,以评估其覆盖范围和效用。此列表中的一个重要参数是“销毁的币天数”(coindays destroyed)。它们的计算方式如下。

考虑加密货币网络中的一个地址以及发生在它身上的事件:代币到达该地址,停留一段时间,然后被转移到其他地址。如果 $x$ 个代币在同一个地址停留了 $y$ 天,那么可以说这些代币积累了 $x \cdot y$ 个币天数的潜力。一旦这 $x$ 个代币被转移到另一个地址,这种潜力就会被销毁:这就是销毁的币天数。同一地址中未参与此次转账的其他代币的潜力不会被销毁,并继续增长。如果一个地址包含来自不同时刻多次转账的代币,则假设转出转账优先使用“最年轻”的代币:即较晚到达的代币。

例如,假设地址 abcdefgh 在周一午夜收到了 5 个 alcoin,在周二午夜又收到了 25 个 alcoin。之后,在周三中午,从该地址取走 2 个 alcoin 并立即转回该地址:此时,销毁了 $2 \cdot 1.5 = 3$ 个币天数。再过半天,在周四午夜,从该地址转出 1 个 alcoin:它销毁了 $1 \cdot 0.5 = 0.5$ 个币天数。最后,假设从 abcdefgh 发出的下一次转账紧接上一次转账之后发生,并取走 28.1 个 alcoin。在此之前,该地址包含以下金额:5 个 alcoin 停留了 3 天,另外 23 个 alcoin 停留了 2 天,以及 $2 - 1 = 1$ 个 alcoin 停留了 0.5 天。结果,此次转账销毁了 58.8 个币天数:$1 \cdot 0.5 + 23 \cdot 2 + 4.1 \cdot 3 = 0.5 + 46 + 12.3 = 58.8$。

在 alcoin 网络中,到目前为止只发生了少数几次转账,计算每次转账销毁的币天数很容易。但 Alya 开始思考:当未来有成千上万次转账时,如何高效地计算这一特征?

解决 Alya 问题的通用版本。给定一个转账列表,找出每次转账销毁的币天数。

输入格式

输入包含 1 到 200 000 行。每一行描述一次转账,格式如下:“m: s |a> r”。其中,$m$ 是转账时刻:一个从 1 到 $2 \cdot 10^9$ 的整数,表示自 1970 年 1 月 1 日开始以来经过的秒数。数字 $a$ 是正在转移的 alcoin 数量:一个小数点后最多有四位数字的实数($10^{-4} \le a \le 10^4$)。最后,$s$ 和 $r$ 分别是发送方地址和接收方地址:它们中的每一个都由恰好八个字符组成,且每个字符要么是数字,要么是小写英文字母。

转账按时间顺序排列。最初,系统中没有 alcoin。保证在每次转账之前,发送方地址包含至少转账所需的 alcoin 数量,除非它是服务地址 00000000

输出格式

对于每次转账,打印一行,包含一个实数:此次转账销毁的币天数。从服务地址 00000000 发出的转账被视为销毁 0 个币天数。如果每个数字的绝对误差或相对误差不超过 $10^{-4}$,则答案将被视为正确。

样例

样例输入 1

1514764800: 00000000 |5.0> abcdefgh
1514851200: 00000000 |25.0> abcdefgh
1514980800: abcdefgh |2.0> abcdefgh
1515024000: abcdefgh |1.0> 00000000
1515024000: abcdefgh |28.1> ijklmnop

样例输出 1

0
0
3
0.5
58.8

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.