#K36892. Warehouse Inventory Queries

    ID: 25855 Type: Default 1000ms 256MiB

Warehouse Inventory Queries

Warehouse Inventory Queries

You are given an array representing the initial stock levels of items in a warehouse. Your task is to process a series of queries that update the inventory and answer range sum queries.

There are two types of queries:

  1. Update Query (Type 1): Update the stock level at index p to a new value v.
  2. Sum Query (Type 2): Calculate the total stock in the inclusive range [p, v].

For every sum query, you should output the answer on a new line. Note that the indices are zero-indexed. In mathematical notation, the range sum query is given by:

$$S = \sum_{i=p}^{v} a_i$$

Solve the problem using efficient update and query techniques, such as a Binary Indexed Tree (Fenwick Tree).

inputFormat

The input is given via standard input and follows the format below:

  • The first line contains an integer n – the number of items in the warehouse.
  • The second line contains n space-separated integers representing the initial stock levels.
  • The third line contains an integer q – the number of queries.
  • Each of the next q lines contains three integers t, p, and v where:
    • If t = 1, update the item at index p to the value v.
    • If t = 2, output the sum of stocks in the range from index p to index v (inclusive).

outputFormat

For each query of type 2, print the corresponding sum on a new line to the standard output.

## sample
5
10 20 30 40 50
4
2 1 3
1 2 25
2 1 3
1 0 100
90

85

</p>