#K69692. Array Query Processing

    ID: 33143 Type: Default 1000ms 256MiB

Array Query Processing

Array Query Processing

You are given an array of n integers and you need to process q queries on the array. There are two types of queries:

  1. Update Query: 0 a b x. For each index \(i\) such that \(a \leq i \leq b\), add \(x\) to \(arr[i]\). This operation can be described by the formula: \(arr[i] = arr[i] + x\) for all \(i\) with \(a \le i \le b\).
  2. Sum Query: 1 a b. Compute and output the sum of the subarray from index \(a\) to \(b\) (inclusive), i.e., compute \(\sum_{i=a}^{b}arr[i]\).

All array indices are 0-based. Process the queries in the order given. For each sum query, you should output the result on a new line.

inputFormat

The input is given via standard input (stdin) and has the following format:

  • The first line contains a single integer \(n\), the number of elements in the array.
  • The second line contains \(n\) space-separated integers representing the array elements.
  • The third line contains a single integer \(q\), the number of queries.
  • The next \(q\) lines each describe a query. For an update query, the query is given as: 0 a b x. For a sum query, the query is given as: 1 a b.

outputFormat

For each sum query (queries beginning with 1), output the computed sum on a separate line to standard output (stdout).

## sample
5
1 2 3 4 5
3
0 1 3 2
1 0 4
1 1 2
21

9

</p>