#P14577. 磁极变换
磁极变换
Description
Morey specializes in magnets.
In the course of the research, Morey has manufactured magnets made of different materials, denoted by the lowercase Latin letters.
Morey has implemented a spectacular technique. First, all the magnets are laid out in a row. When a button is pressed, then for each material type separately, the 1st, 3rd, 5th, ... occurrences become north-poles (N), and the 2nd, 4th, 6th, ... occurrences become south-poles (S). Then, for each material separately, for each positive integer , the -th and the -th magnets of that material attract each other and move toward each other until they collide—if both exist. During the collision, all magnets in the interval between them (inclusive) are destroyed. All such collisions happen simultaneously.
In addition, the -th magnet has an associated value .
If we represent the sequence of magnet materials by a string , we denote by the sum of the values of the magnets that remain after applying this technique.
Now, there are magnets placed in the machine in positions through . You are given their material types and values.
Morey wants to process two types of operations:
Update: Change the value of a single magnet.
Query: For a given index interval , apply the technique only to the magnets in that interval, and report the sum of the values of the magnets that remain in that interval, i.e. .
Formally, the operations are:
-
1 x y: Set . -
2 l r: Output .
Input Format
The first line contains a positive integer , the number of magnets.
The second line contains a string of length , consisting of lowercase letters, where is the material of the -th magnet.
The third line contains integers , the initial values of the magnets.
The fourth line contains a positive integer , the number of operations.
Each of the next lines contains three integers describing one operation as above.
Output Format
For each query, output one line containing the integer .
6
iakioi
1 -4 2 7 -5 3
3
2 1 6
2 1 5
2 3 6
-2
-5
2
6
ecbeca
-1 -6 4 8 2 5
3
2 1 6
1 6 4
2 1 6
5
4
Hint
Hint: Please use faster input/output methods.
Explanation of Examples

For Sample 1:
-
Query : Material
ioccurs at positions . Magnets at positions and attract and collide, destroying everything between them (i.e., positions ). Only magnets at positions and remain , so the remaining sum is . -
Query : Material
ioccurs at positions and . Magnets at positions and attract and collide, destroying everything between them (i.e., positions ). Only magnets at positions remains with value .
For Sample 2: Magnets at positions and attract and collide, destroying everything between them (i.e., positions ). Meanwhile, Magnets at positions and attract and collide, destroying everything between them (i.e., positions ). Only position remains.
| Subtask | Special Properties | Score | Time Limit | ||
|---|---|---|---|---|---|
| Subtask 1 | None | 0.6s | |||
| Subtask 2 | |||||
| Subtask 3 | A | 1.2s | |||
| Subtask 4 | None | ||||
| Subtask 5 | B | ||||
| Subtask 6 | None | ||||
Special Property A: contains only the first letters of the alphabet.
Special Property B: There are no update operations.
For all data, , , and consists only of lowercase Latin letters.
京公网安备 11011102002149号