843. Range XOR Queries With Subarray Reversals
You are given an integer arrayΒ numsΒ of lengthΒ nΒ and a 2D integer arrayΒ queriesΒ of lengthΒ q, where each query is one of the following three types:
- Update:Β queries[i] = [1, index, value]
- SetΒ nums[index] = value.
- Range XOR Query:Β queries[i] = [2, left, right]
- Compute the bitwise XOR of all elements in theΒ subarrayΒ nums[left...right], and record this result.
- Reverse Subarray:Β queries[i] = [3, left, right]
- Reverse theΒ subarrayΒ nums[left...right]Β in place.
ReturnΒ an array of the results of all range XOR queriesΒ in the order they were encountered.
Example 1:
Input:Β nums = [1,2,3,4,5], queries = [[2,1,3],[1,2,10],[3,0,4],[2,0,4]]
Output:Β [5,8]
Explanation:
- QueryΒ 1:Β [2, 1, 3]Β β Compute XOR of subarrayΒ [2, 3, 4]Β resulting in 5.
- Query 2:Β [1, 2, 10]Β β UpdateΒ nums[2]Β to 10, updating the array toΒ [1, 2, 10, 4, 5].
- Query 3:Β [3, 0, 4]Β β Reverse the entire array to getΒ [5, 4, 10, 2, 1].
- Query 4:Β [2, 0, 4]Β β Compute XOR of subarrayΒ [5, 4, 10, 2, 1]Β resulting in 8.
Example 2:
Input:Β nums = [7,8,9], queries = [[1,0,3],[2,0,2],[3,1,2]]
Output:Β [2]
Explanation:
- Query 1:Β [1, 0, 3]Β β UpdateΒ nums[0]Β to 3, updating the array toΒ [3, 8, 9].
- Query 2:Β [2, 0, 2]Β β Compute XOR of subarrayΒ [3, 8, 9]Β resulting in 2.
- Query 3:Β [3, 1, 2]Β β Reverse the subarrayΒ [8, 9]Β to getΒ [9, 8].
Now Your Turn!
Pick the correct output for the given inputInput: nums = [1,2,3], queries = [[2,1,2]]
Still unsure what the problem is asking ?
Letβs go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= nums.length <= 105
- 0 <= nums[i] <= 109
- 1 <= queries.length <= 105
- queries[i].length == 3β
- queries[i][0] β {1, 2, 3}β
- IfΒ queries[i][0] == 1:β
- 0 <= index < nums.lengthβ
- 0 <= value <= 109
- IfΒ queries[i][0] == 2Β orΒ queries[i][0] == 3:β
- 0 <= left <= right < nums.lengthβ