#K40677. Range Sum Queries with Point Updates

    ID: 26696 Type: Default 1000ms 256MiB

Range Sum Queries with Point Updates

Range Sum Queries with Point Updates

You are given a list of integers and a sequence of operations. There are two types of operations:

  • 1 x y: Update the element at position x to value y.
  • 2 l r: Compute the sum of elements in the range from l to r (both inclusive).

You need to process m operations on a list of n integers. The operations will be provided in order, and for each range sum query, you should output the result on its own line.

This problem can be solved efficiently using a Fenwick Tree (or Binary Indexed Tree). The update and query operations of a Fenwick Tree work in O(\(\log n\)) time. In this problem, you are required to implement this data structure to pass all test cases.

Note: All array indices are 1-indexed.

inputFormat

The input is given via stdin in the following format:

n m
a1 a2 ... an
op1
op2
...
opm

Where:

  • The first line contains two integers n and m, representing the number of elements and the number of operations respectively.
  • The second line contains n integers, representing the initial list.
  • The next m lines contain an operation each. Each operation is in one of the following forms:
    • 1 x y for updating the element at index x to y.
    • 2 l r for computing the sum from index l to r (both inclusive).

outputFormat

For each range sum query (i.e. operations starting with 2), output the corresponding sum on a new line to stdout.

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

14 13 19

</p>