#K41512. Badge System Query Processing
Badge System Query Processing
Badge System Query Processing
You are given an integer n
representing the length of a string S
consisting of digits, and an integer q
representing the number of queries. The string S
represents a badge system. You are then provided q
queries which can be of two types:
- Type 1:
1 i j
— Compute the sum of the digits from index \(i\) to \(j\) (inclusive). Here, indices are 0-based. - Type 2:
2 i j k
— Replace every digit from index \(i\) to \(j\) (inclusive) with the digitk
.
After processing all queries in order, you should output the results of every Type 1 query. The input is provided via standard input and the output must be printed to standard output.
For example, given n = 5
, S = "12345"
, and the following queries:
1 0 2 2 1 3 9 1 1 4 1 0 4
The result for each type 1 query would be:
- Sum from index 0 to 2: \(1 + 2 + 3 = 6\)
- After replacement, sum from index 1 to 4: \(9 + 9 + 9 + 5 = 32\)
- Finally, sum from index 0 to 4: \(1 + 9 + 9 + 9 + 5 = 33\)
Your task is to implement the query processing as described.
inputFormat
The input is read from standard input and has the following format:
n q S query_1 query_2 ... query_q
Where:
n
andq
are integers representing the length of the string and the number of queries respectively.S
is a string of digits with lengthn
.- Each
query
is either in the format1 i j
or2 i j k
as described above.
outputFormat
For each query of type 1, output the sum of the specified segment of the string on a separate line to standard output.
## sample5 4
12345
1 0 2
2 1 3 9
1 1 4
1 0 4
6
32
33
</p>