We’re preparing your current view and syncing the latest data.
Given an integer array nums, handle multiple queries of two types:
Initialization: An integer array nums. Operations: update(index, val) and sumRange(left, right).
For sumRange operations, return the sum of specified range. For update operations, no return output.
1 <= nums.length <= 3 * 10^4 -10^5 <= nums[i] <= 10^5 0 <= index < nums.length -10^5 <= val <= 10^5 0 <= left <= right < nums.length At most 3 * 10^4 calls will be made to update and sumRange combined.
Example 1
Input
NumArray([1, 3, 5]) sumRange(0, 2) update(1, 2) sumRange(0, 2)
Output
9 (After sumRange(0, 2), output is 9) (None for update) 8 (After update(1, 2), sumRange(0, 2) outputs 8)
Explanation
Initially, sumRange(0, 2) = 1 + 3 + 5 = 9. After updating index 1 from 3 to 2, the array becomes [1, 2, 5]. Now sumRange(0, 2) = 1 + 2 + 5 = 8.