#P3374. Range Sum Query and Point Update

    ID: 16631 Type: Default 1000ms 256MiB

Range Sum Query and Point Update

Range Sum Query and Point Update

You are given an array of integers. You need to perform two types of operations:

  • Update Operation: Given an index i and a value x, add x to the element at index i. Mathematically, if the array is \( A \), then this operation updates \( A[i] \) as follows: \( A[i] = A[i] + x \).
  • Query Operation: Given a range \( [l, r] \), compute the sum of all elements from index l to index r (inclusive), i.e., output \( \sum_{j=l}^{r} A[j] \).

Note: The indices are 1-based.

inputFormat

The first line contains two integers n and q where n is the number of elements in the array and q is the number of operations.

The second line contains n integers representing the elements of the array.

Each of the following q lines represents an operation in one of the following formats:

  • 1 i x — update operation: add x to the number at index i.
  • 2 l r — query operation: output the sum of numbers from index l to r (inclusive).

All indices are 1-based.

outputFormat

For each query operation (type 2), output the result on a separate line.

sample

5 5
1 2 3 4 5
2 1 5
1 3 10
2 2 4
1 5 2
2 3 5
15

19 24

</p>