#C489. Array Manipulation with Update and Query Operations
Array Manipulation with Update and Query Operations
Array Manipulation with Update and Query Operations
You are given an array of n integers. You need to process a series of operations on this array. There are two types of operations:
- Update x y: Update the element at index x to value y. (Note that the array is 1-indexed.)
- Query l r: Calculate and print the sum of the elements from index l to r (inclusive).
The operations are given in order, and you need to execute them. For each "Query" operation, output the resulting sum.
Note: The input and output must be handled via standard input (stdin) and standard output (stdout).
The update operation modifies the array, and subsequent queries will reflect the changes.
For example, given the array \( A = [1, 2, 3, 4, 5] \) and operations:
\[ Query\; 1\; 3, \quad Update\; 2\; 10, \quad Query\; 1\; 3 \]the results will be:
\[ 6 \quad 14 \]inputFormat
The first line contains an integer n representing the number of elements in the array.
The second line contains n space-separated integers representing the array.
The third line contains an integer m representing the number of operations.
The next m lines each contain an operation in one of the following formats:
Update x y
: Update the element at position x to y.Query l r
: Output the sum of elements from index l to r (inclusive).
outputFormat
For each "Query" operation in the input, output the resulting sum on a new line.
## sample5
1 2 3 4 5
3
Query 1 3
Update 2 10
Query 1 3
6
14
</p>