#P6357. Range Query with Increment Twist
Range Query with Increment Twist
Range Query with Increment Twist
You are given a string of digits of length \(n\) (each digit is between 0 and 9) with indices starting from \(1\). You need to process \(m\) queries. For each query, you are given two indices \(A\) and \(B\):
- Compute the sum of the digits in the interval \([A, B]\) based on the current state of the string.
- After calculating the sum, increment each digit in the interval by 1. However, if a digit is \(9\) before incrementing, it wraps around to \(0\) after incrementing.
Output the computed sum for each query.
inputFormat
The first line contains two integers \(n\) and \(m\) separated by a space.
The second line contains a string of \(n\) digits (each digit ranges from 0 to 9) without spaces.
The following \(m\) lines each contain two integers \(A\) and \(B\), representing the query interval.
outputFormat
For each query, output the sum of the digits in the specified interval \([A, B]\) (before performing the increment) on a new line.
sample
5 3
12345
1 3
2 5
1 5
6
16
22
</p>