#K8166. Segment Tree Queries

    ID: 35803 Type: Default 1000ms 256MiB

Segment Tree Queries

Segment Tree Queries

This problem involves implementing a segment tree to efficiently handle update and range sum queries on an array. You are given an array of integers and a sequence of queries. There are two types of queries:

  • update x y: Update the element at index x to y.
  • sum l r: Compute the sum of the elements in the range from index l to r (inclusive), i.e. $$\sum_{i=l}^{r} a_i$$.

Your task is to process all the queries. For each sum query, output the computed sum on a new line.

inputFormat

The first line contains two integers N and Q, where N is the size of the array and Q is the number of queries.

The second line contains N space-separated integers representing the initial array.

The following Q lines each contain a query in one of the following formats:

  • update x y: update the element at index x to y.
  • sum l r: output the sum of the elements from index l to r (inclusive).

outputFormat

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

## sample
5 4
1 2 3 4 5
sum 1 3
update 2 6
sum 2 4
sum 0 4
9

15 18

</p>