#K55027. Array Update and Range Sum Queries
Array Update and Range Sum Queries
Array Update and Range Sum Queries
You are given an array \(A\) of \(N\) integers and a constant \(K\). Initially, each element \(a_i\) of the array is increased by \(K\), i.e., \(a_i = a_i + K\) for \(1 \le i \le N\). You are then given \(Q\) operations, each of which is one of the following two types:
- Update Operation:
1 l r x
— Add \(x\) to every element in the subarray from index \(l\) to \(r\) (both indices inclusive). (The indices are 1-indexed.) - Sum Query:
2 l r
— Compute and output the sum of the elements in the subarray from index \(l\) to \(r\) (1-indexed).
Your task is to process all the operations in the order given and output the result of each sum query. Note that the update operations affect the subsequent queries.
inputFormat
The input is given via standard input in the following format:
N Q K A[1] A[2] ... A[N] op1 op2 ... opQ
Here:
- The first line contains three integers \(N\), \(Q\), and \(K\).
- The second line contains \(N\) integers representing the array \(A\).
- Each of the following \(Q\) lines represents an operation. An operation of type update is given in the form
1 l r x
, and an operation of type query in the form2 l r
.
Note: All indices are 1-indexed.
outputFormat
For each query operation (operation type 2), output the resulting sum on a separate line to standard output.
## sample5 5 2
1 2 3 4 5
2 1 3
1 2 4 1
2 1 3
1 3 5 -2
2 3 5
12
14
14
</p>