StripeOA #17
For All Intents And Purposes Part 1 - Initializing the System
估计简单可在线判题
考点(AI 标注)迭代器设计模拟/实现
Execute the interrelated Payment Intent commands from Parts 1–4 of the original Stripe problem. An Intent's states are REQUIRES_ACTION, PROCESSING, and COMPLETED; illegal state transitions and invalid creations/updates are ignored. Command timestamps are strictly increasing. A refund can succeed only for a completed Intent that has not been refunded yet, and it is judged against the merchant's refund time limit.
输入格式
The first line contains q (1..200000), followed by q lines of commands: timestamp INIT merchant starting_balance [refund_limit], timestamp CREATE intent merchant amount, timestamp ATTEMPT intent, timestamp SUCCEED intent, timestamp FAIL intent, timestamp UPDATE intent new_amount, or timestamp REFUND intent. An ID is a string without whitespace. Balances, amounts, and refund limits are signed 64-bit integers. Only a merchant's first INIT takes effect; duplicate merchants, duplicate Intent IDs, unknown merchants, and negative creation amounts are ignored. A missing or negative refund limit means no time limit, 0 means refunds are not allowed, and a positive n means the refund timestamp must be no later than the success timestamp+n.
输出格式
First output the number of initialized merchants; then output merchant_id balance line by line in lexicographic order of merchant ID.
样例 1
输入:
5
1 INIT m1 0
2 CREATE p1 m1 50
3 UPDATE p1 100
4 ATTEMPT p1
5 SUCCEED p1
输出:
1
m1 100
样例 2
输入:
9
1 INIT m1 0 5
2 CREATE p1 m1 100
3 CREATE p2 m1 50
4 ATTEMPT p1
5 ATTEMPT p2
8 SUCCEED p1
10 SUCCEED p2
11 REFUND p1
16 REFUND p2
输出:
1
m1 50
样例 3
输入:
11
1 INIT m2 10 -1
2 INIT m1 5 0
3 CREATE p m2 20
4 ATTEMPT p
5 FAIL p
6 UPDATE p 30
7 ATTEMPT p
8 SUCCEED p
9 SUCCEED p
10 REFUND p
11 REFUND p
输出:
2
m1 5
m2 10