cswork / OA打开练习工作台

RampOA #2

Bot Bank — Deposit/Withdraw with Cashback (Stateless solution)

估计中等可在线判题

考点(AI 标注)模拟/实现哈希计数

Process bank deposits and withdrawals in time order. A successful withdrawal refunds 2% of the withdrawn amount (rounded down) 24 hours later; when a cashback is due, apply it before processing a request in the same second. At the first request with an invalid account or insufficient balance, return the negative of its 1-based request index.

输入格式

The first line contains N Q (on this site: 1≤N≤100000, 0≤Q≤200000); the second line contains N initial non-negative balances (each ≤10^12). Then Q lines follow: operation timestamp holder_id amount. operation is deposit or withdraw; timestamp is a strictly increasing positive integer number of seconds (≤10^12); amount is a non-negative integer (≤10^9); holder_id is an integer, where 1..N are valid accounts and any other value is treated as an invalid account, as the problem specifies.

输出格式

Output a JSON integer array. If all requests are valid, return the account balances after the last request's timestamp has been processed; if request i is the first invalid one, output [-i]. Cashbacks that only become due after the last request are not included in the final balances.

样例 1

输入:

1 2
200
withdraw 1 1 100
withdraw 86401 1 100

输出:

[2]

样例 2

输入:

1 1
49
withdraw 1 1 49

输出:

[0]

样例 3

输入:

1 1
100
deposit 1 0 1

输出:

[-1]

样例 4

输入:

1 1
49
withdraw 1 1 50

输出:

[-1]

样例 5

输入:

1 2
100
deposit 1 1 5
withdraw 2 2 1

输出:

[-2]

样例 6

输入:

1 1
100
withdraw 1 1 100

输出:

[0]

样例 7

输入:

1 2
100
withdraw 1 1 100
deposit 86402 1 5

输出:

[7]

样例 8

输入:

2 2
10 10
deposit 1 1 3
withdraw 2 2 10

输出:

[13,0]

样例说明

Use a min-heap to manage cashback due times.