#K86847. Efficient Array Queries

    ID: 36955 Type: Default 1000ms 256MiB

Efficient Array Queries

Efficient Array Queries

You are given an array \(A\) of \(n\) integers. Your task is to process \(q\) queries efficiently. There are two types of queries:

  • Update query: 0 i x — update the element at index \(i\) (0-indexed) to the value \(x\);
  • Sum query: 1 l r — compute the sum \(\sum_{k=l}^{r} A_k\) (inclusive).

You are required to design a solution that supports both operations in an efficient manner (hint: use a Fenwick Tree or Binary Indexed Tree). The sum query can be mathematically represented as:

[ S(l, r) = \sum_{k=l}^{r} A_k ]

Note: The indices provided are 0-indexed.

inputFormat

The input is given via stdin in the following format:

n q
A0 A1 ... An-1
query1
query2
... 
queryq

Each query is either of the form 0 i x for an update operation or 1 l r for a sum query. It is guaranteed that the queries are valid.

outputFormat

For each sum query, output the resulting sum on a new line to stdout.

## sample
5 5
1 2 3 4 5
1 1 3
0 2 -2
1 1 3
0 4 10
1 3 4
9

4 14

</p>