#C5491. Array Query Processor
Array Query Processor
Array Query Processor
You are given an array of N integers and a series of queries. There are two types of queries:
- sum_range l r: Compute the sum of the array elements from index l to r (inclusive). Note that the indices are 1-indexed. In mathematical terms, you need to compute \( \sum_{i=l}^{r} a_i \).
- increment x y: Increase each element of the array from index x to y (inclusive) by 1.
Your task is to process all the queries in the given order. For every sum_range
query, you should output the computed sum on a new line.
Note: The operations are applied sequentially, meaning that the changes made by an increment
query affect the subsequent queries.
inputFormat
The input is given in the following format from standard input:
- An integer N representing the number of elements in the array.
- A line with N space-separated integers, representing the elements of the array.
- An integer Q representing the number of queries.
- Q lines, each containing a query. Each query is in one of the following formats:
sum_range l r
increment x y
outputFormat
For each sum_range
query, output the corresponding sum on a new line to standard output.
5
1 2 3 4 5
6
sum_range 1 3
increment 2 4
sum_range 2 5
increment 1 5
sum_range 1 5
sum_range 3 4
6
17
23
11
</p>