#K55197. Query Processor on Integer List
Query Processor on Integer List
Query Processor on Integer List
You are given an array of (n) integers and a series of operations. There are two types of operations:
-
Update: Denoted by a line starting with the integer 1. This is followed by two integers (i) and (x). You need to update the (i)-th element of the array (1-indexed) to (x).
-
Query: Denoted by a line starting with the integer 2. This is followed by two integers (L) and (R). For this operation, you need to calculate and output the sum of the elements from index (L) to (R) (both inclusive).
The task is to process all these operations efficiently. Updates must adjust any precomputed data, and queries must produce the correct sum over the current configuration of the array.
Use the following input and output format to solve the problem.
inputFormat
The input is given from standard input (stdin) and follows the format below:
The first line of input contains a single integer (n), the number of elements in the array.
The second line contains (n) space-separated integers representing the initial array.
The third line contains a single integer (q), the number of operations.
Each of the following (q) lines contains an operation. An operation is given in one of the following two formats:
- For an update operation:
1 i x
- For a query operation:
2 L R
All indices are 1-indexed.
outputFormat
For each query operation (operations beginning with 2), output the result of the query on a separate line to standard output (stdout).## sample
5
1 -2 3 4 5
4
2 1 3
1 2 10
2 1 3
2 2 5
2
14
22
</p>