#FT0000005. Robin Hood tò mò (Curious Robin Hood)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Robin Hood tò mò (Curious Robin Hood)
Curious Robin Hood
Source: LightOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Robin Hood stores his money in sacks, numbered through . Initially, sack holds coins. Process actions in the order supplied.
Command 1 i: remove all coins currently in sack and give them away. Print the amount removed and set that sack's contents to . If the sack is already empty, the reported amount is .
Command 2 i v: add coins to sack , leaving every other sack unchanged. Command 3 i j: report the total number of coins now contained in sacks through , including both endpoints, without changing the sacks.
Output the results of commands 1 and 3 in their occurrence order, using the current state after preceding actions.
Input
- Line 1:
n qgives number of sacks and commands. - Line 2:
a_0 a_1 ... a_(n-1)gives the initial values in index order. - Next lines: each line contains one of the following commands, in execution order:
1 i: empty sack and output the amount removed.2 i v: add coins to sack .3 i j: calculate the total number of coins in sacks through , including both endpoints.
Output
Command 1 i outputs the number of coins removed before emptying sack . Command 3 i j outputs the current sum of money in sacks through . Print one line for each such command in input order. Command 2 has no output.
Subtasks
Subtask 1 (20 points):
- .
- .
- .
- .
- in command
3. - in command
1,2.
Subtask 2 (30 points):
- .
- .
- .
- .
- in command
3. - in command
1,2.
Subtask 3 (50 points):
- .
- .
- .
- .
- in command
3. - in command
1,2.
Examples
Input
5 7
3 2 1 4 5
1 4
2 3 4
3 0 3
1 2
3 0 4
2 0 3
3 0 1
Output
5
14
1
13
8
Explanation
There are elements. The initial values are [3, 2, 1, 4, 5].
-
Command 1 —
1 4: Sack contains coins. Remove and print5, then set the sack to :[3, 2, 1, 4, 0]. -
Command 2 —
2 3 4: Add coins to sack : . The sacks now hold[3, 2, 1, 8, 0]. -
Command 3 —
3 0 3: Sum sacks through : . Print14without changing any sack. -
Command 4 —
1 2: Sack contains coins. Remove and print1, then set the sack to :[3, 2, 0, 8, 0]. -
Command 5 —
3 0 4: Sum sacks through : . Print13without changing any sack. -
Command 6 —
2 0 3: Add coins to sack : . The sacks now hold[6, 2, 0, 8, 0]. -
Command 7 —
3 0 1: Sum sacks through : . Print8without changing any sack.
Collect the answers to output-producing commands in their input order, printing one answer per line.