#P6357. [COCI 2007/2008 #3] REDOKS
[COCI 2007/2008 #3] REDOKS
Problem Description
You are given a sequence of digits of length . Each digit is any one of , and the indices start from .
Then perform range queries. For each query, find the sum of the digits in the range , and after the query, add to every digit in this range. In particular, if a digit is before adding , then it becomes after adding .
Output the range sum for each query.
Input Format
The first line contains two integers .
The second line contains digit characters, with no spaces between them.
The next lines each contain two integers , representing the query range .
Output Format
Output lines in total. Each line contains the range sum for one query.
4 3
1234
1 4
1 4
1 4
10
14
18
4 4
1234
1 1
1 2
1 3
1 4
1
4
9
16
7 5
9081337
1 3
3 7
1 3
3 7
1 3
17
23
1
19
5
Hint
Constraints
For of the testdata, it is guaranteed that , , and .
Notes
This problem is translated from COCI2007-2008 CONTEST #3 T6 REDOKS。
Translated by ChatGPT 5