#C8733. Efficient Query Processing
Efficient Query Processing
Efficient Query Processing
This problem requires you to efficiently perform two types of operations on an array: updating an element and querying the sum of a subarray. You are given an array of integers and a series of operations. For each update operation, you must change the value at a specified index, and for each sum query, you must report the sum of the subarray defined by two indices.
Operations:
1 X Y: Update the element at position X to Y.
2 L R: Output the sum of the subarray from index L to R (inclusive).
Due to the constraints, a naive approach may not be efficient enough. Consider using a Binary Indexed Tree (Fenwick Tree) to handle the operations efficiently. The update and sum operations can be performed in O(log n) time.
inputFormat
The input is given via standard input and has the following format:
- The first line contains two integers n and m, where n is the number of elements in the array and m is the number of operations.
- The second line contains n integers, representing the initial elements of the array.
- The following m lines each represent an operation in one of the two forms:
1 X Y
: Update the element at index X to the new value Y.2 L R
: Query and output the sum of the subarray from index L to R (inclusive).
outputFormat
For each query operation (of type 2), output a single line containing the sum of the subarray from index L to R.
## sample5 6
1 2 3 4 5
2 1 3
1 3 10
2 1 3
2 3 5
1 5 20
2 3 5
6
13
19
34
</p>