#K43437. Array Query Processing
Array Query Processing
Array Query Processing
You are given an array of n integers and q queries. The array is 1-indexed. There are two types of queries:
- Update Query (type 1): The query is given in the form:
1 l r x
. For each index i in the subarray from l to r (inclusive), add x to array[i]. - Sum Query (type 2): The query is given in the form:
2 l r
. Calculate the sum of elements from index l to r (inclusive) and output the result.
The queries are processed in the order they are provided, and the modifications affect subsequent queries. Formally, if you denote the array as \(A[1 \ldots n]\), then for each update query the following operation is performed:
[ A[i] = A[i] + x \quad \text{for all } i \text{ such that } l \le i \le r, ]
For each sum query, output the result in a new line.
inputFormat
The input is read from standard input (stdin) and is formatted as follows:
n a1 a2 ... an q (query 1) (query 2) ... (query q)
Here, n is the number of elements in the array, and the second line contains n integers. Next, q specifies the number of queries. Each query is given on a new line. A query is either in the format 1 l r x
for an update, or 2 l r
for a sum query.
outputFormat
For each sum query, output the corresponding result on a new line to standard output (stdout).
## sample5
1 2 3 4 5
3
1 1 3 10
2 1 3
2 4 5
36
9
</p>