#C10947. Processing Array Queries

    ID: 40208 Type: Default 1000ms 256MiB

Processing Array Queries

Processing Array Queries

You are given an array of n integers and a series of q queries. There are two types of queries:

  • Update query: The query is in the form 1 i x, which means add the value x to the element at index i (1-indexed).
  • Sum query: The query is in the form 2 l r, which asks you to calculate the sum of the subarray from index l to r (inclusive, 1-indexed). Formally, you need to compute \(\sum_{i=l}^{r} a_i\).

After processing all queries, output the result of each sum query in the order they appear. Note that update queries modify the array permanently before subsequent queries.

Examples:

Input:
5
1 2 3 4 5
4
2 1 3
1 2 5
2 1 3
2 3 5

Output: 6 11 12

Explanation: Initially, the array is [1, 2, 3, 4, 5]. The first query outputs the sum of elements from index 1 to 3: 1+2+3 = 6. After the update query (adding 5 to index 2), the array becomes [1, 7, 3, 4, 5]. The next query gives 1+7+3 = 11, and the last query sums 3+4+5 = 12.

</p>

inputFormat

The input is given via standard input (stdin) in the following format:

  1. An integer n denoting the size of the array.
  2. A line containing n space-separated integers representing the array elements.
  3. An integer q denoting the number of queries.
  4. q lines follow, each representing a query:
    • For an update query: 1 i x
    • For a sum query: 2 l r

outputFormat

For each sum query, print the corresponding sum on a separate line to standard output (stdout).

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

11 12

</p>