#FT0000022. Các loại đá quý của trợ thủ (Just for Sidekicks)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các loại đá quý của trợ thủ (Just for Sidekicks)
Just for Sidekicks
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
You have a row of gems, at positions numbered from through . Each gem belongs to one of six types, labeled by the digits 1 through 6. Initially type has value ; a string specifies the type of the gem at each position.
Process commands in order. Command 1 k p changes the gem at position to type , without altering the listed price of type . Command 2 p v changes the price of the entire gem type to : every gem currently of that type is now valued at the new price, even though none changes type or location.
Command 3 l r asks for the sum of the current gem values in positions through inclusive. Each gem's value is always determined by the current price of its type at the time of the query.
Input
- Line 1:
n qgives number of gems and commands. - Line 2:
v_1 v_2 v_3 v_4 v_5 v_6gives the initial prices of gem types1through6. - Line 3: a string
Sof exactly digits from1through6; the -th digit is the gem type at position . - Next lines: each line contains one of the following commands, in execution order:
1 k p: change the gem at position to type .2 p v: set the price of gem type to .3 l r: query the gem value from through .
Output
For each 3 l r command, print the requested integer computed from the current state on its own line, in query order. Update commands produce no output.
Subtasks
Subtask 1 (20 points):
- .
- .
- for all .
- the gem string contains exactly characters, each in .
- command
1: , . - command
2: . - command
3: .
Subtask 2 (30 points):
- .
- .
- for all .
- the gem string contains exactly characters, each in .
- command
1: , . - command
2: . - command
3: .
Subtask 3 (50 points):
- .
- .
- for all .
- the gem string contains exactly characters, each in .
- command
1: , . - command
2: . - command
3: .
Examples
Input
5 7
1 2 3 4 5 6
12361
3 1 5
2 6 10
3 2 4
1 1 6
3 1 2
2 1 20
3 1 5
Output
13
15
12
45
Explanation
There are gems with type string 12361, representing types [1,2,3,6,1]. Their initial type prices are [1,2,3,4,5,6].
-
3 1 5: the gem values are ; their sum is . Print13. -
2 6 10: the price of type 6 changes from to ; the type string remains12361. -
3 2 4: the gem types at positions 2, 3, and 4 are[2,3,6], with current prices ; the sum is . Print15. -
1 1 6: change the first gem from type 1 to type 6, making the string62361. -
3 1 2: the first two gem values are and , summing to . Print12. -
2 1 20: type 1's price changes from to . The last gem is type 1 and is now worth , without changing its type. -
3 1 5: the types[6,2,3,6,1]currently have values . Their sum is . Print45.
The four query answers are 13, 15, 12, and 45.