#P6357. [COCI 2007/2008 #3] REDOKS

[COCI 2007/2008 #3] REDOKS

Problem Description

You are given a sequence of digits of length nn. Each digit is any one of 090 \sim 9, and the indices start from 11.

Then perform mm range queries. For each query, find the sum of the digits in the range [A,B][A, B], and after the query, add 11 to every digit in this range. In particular, if a digit is 99 before adding 11, then it becomes 00 after adding 11.

Output the range sum for each query.

Input Format

The first line contains two integers n,mn, m.

The second line contains nn digit characters, with no spaces between them.

The next mm lines each contain two integers A,BA, B, representing the query range [A,B][A, B].

Output Format

Output mm 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 100%100\% of the testdata, it is guaranteed that 1n2.5×1051 \le n \le 2.5 \times 10^5, 1m1051 \le m \le 10^5, and 1A,Bn1 \le A, B \le n.

Notes

This problem is translated from COCI2007-2008 CONTEST #3 T6 REDOKS

Translated by ChatGPT 5