#K35957. Segment Tree for Range Sum Query and Update

    ID: 25646 Type: Default 1000ms 256MiB

Segment Tree for Range Sum Query and Update

Segment Tree for Range Sum Query and Update

You are given an array of n integers. You need to process q operations on this array. There are two types of operations:

  • Update Operation: Type 1 operation of the form 1 index value means update the element at position index to the given value.
  • Query Operation: Type 2 operation of the form 2 left right means calculate the sum of the elements from left to right (both inclusive).

Your task is to implement these operations efficiently using a segment tree. In particular, your implementation must handle both update and range sum query operations. The final output should print the result of each query operation to stdout, each on a new line.

Note: All array indices in the operations are 1-indexed.

inputFormat

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

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

The following q lines each describe an operation in one of the following two formats:

  • 1 index value — Update the element at the given index to value.
  • 2 left right — Query and print the sum from left to right (inclusive).

outputFormat

For every query operation (type 2), output the resulting sum on a new line.

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

14 25

</p>