#K66592. Range Sum Query with Updates

    ID: 32454 Type: Default 1000ms 256MiB

Range Sum Query with Updates

Range Sum Query with Updates

You are given an array of n integers and a series of queries. There are two types of queries:

  1. Update Query: Given in the form 1 i x, update the value at index i to x.
  2. Sum Query: Given in the form 2 l r, compute the sum of the array elements from index l to r (inclusive).

You may use a simple prefix sum technique, even if the update operations require recomputation. Specifically, the prefix sum is defined as \[ P[i] = \sum_{j=1}^{i} a_j, \] with the recurrence \(P[i] = P[i-1] + a_i\). Each update query requires adjusting the prefix sums accordingly. The input is read from standard input (stdin) and the output should be written to standard output (stdout).

inputFormat

The input is given via standard input:

  • The first line contains an integer n — the number of elements in the sequence.
  • The second line contains n space-separated integers representing the sequence.
  • The third line contains an integer q — the number of queries.
  • The next q lines each represent a query in one of the two formats:
    • 1 i x — update the element at index i to x.
    • 2 l r — output the sum of the elements from index l to r.

outputFormat

For each query of the second type (2 l r), output the sum of elements in the range [l, r] on a separate line via standard output.

## sample
5
1 2 3 4 5
3
2 1 5
1 3 10
2 1 5
15

22

</p>