#C8378. Taco Array Manipulation
Taco Array Manipulation
Taco Array Manipulation
You are given an array of n integers and need to perform q commands on it. Commands are of two types:
- Update Command: The command '0 i x' updates the element at index i to x.
- Sum Query Command: The command '1 b e' outputs the sum of the subarray from index b to e-1.
All indices are 0-indexed. The sum of elements in a given range can be expressed using the formula: ( S = \sum_{i=b}^{e-1} a_i ).
Read all input from standard input (stdin) and print the required outputs for each sum query to standard output (stdout).
For example, given the array [2, 4, 7, 3, 5, 1] and the queries:
1 1 4 0 2 10 1 1 4 1 0 6
The output will be: 14 17 25
inputFormat
The first line contains an integer n, the number of elements in the array. The second line contains n space-separated integers representing the array. The third line contains an integer q, the number of commands. Each of the next q lines contains three integers: command, p, and q. If the command is 0, update the element at index p to q. If the command is 1, compute the sum of the subarray from index p to q-1.
outputFormat
For each command of type 1, output the resulting sum on a new line.## sample
6
2 4 7 3 5 1
4
1 1 4
0 2 10
1 1 4
1 0 6
14
17
25
</p>