#K93337. Range Sum Query and Update

    ID: 38397 Type: Default 1000ms 256MiB

Range Sum Query and Update

Range Sum Query and Update

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

  • sum l r: Calculate the sum of the array elements from index l to r (inclusive). The sum is defined by the formula $$S = \sum_{i=l}^{r} a_i$$.
  • upd i val: Update the element at index i to a new value val.

The task is to process all the queries in order and print the output for each sum query on a new line. Note that the update queries do not produce an output.

Example:

Input:
3
1 3 5
3
sum 0 2
upd 1 2
sum 0 2

Output: 9 8

</p>

Implement the functionality so that it handles the queries correctly.

inputFormat

The first line contains an integer n representing the number of elements in the array.

The second line contains n space-separated integers representing the array elements.

The third line contains an integer q representing the number of queries.

Each of the next q lines represents a query in one of the following two formats:

  • sum l r where l and r are integers denoting the start and end indices respectively.
  • upd i val where i is the index and val is the new value.

outputFormat

For every sum query, output the result on a new line.

## sample
3
1 3 5
3
sum 0 2
upd 1 2
sum 0 2
9

8

</p>