1310 XOR Queries of a Subarray
Given the array arr
of positive integers and the array queries
where queries[i] = [Li, Ri]
, for each query i
compute the XOR of elements from Li
to Ri
(that is, arr[Li]
xor
arr[Li+1]
xor
...
xor
arr[Ri]
). Return an array containing the result for the given queries
.
Example 1:
Example 2:
Constraints:
1 <= arr.length <= 3 * 10^4
1 <= arr[i] <= 10^9
1 <= queries.length <= 3 * 10^4
queries[i].length == 2
0 <= queries[i][0] <= queries[i][1] < arr.length
这题一看,感觉套路怎么这么像prefix Sum,但是这里换了xor。自己算了一下发现,其实xor也有加法性质。(note:另外log也有,提醒自己一下)一开始用0就ok了,因为0异或任何数等于任何数。T:O(n), S:O(n)
Last updated