1310. XOR Queries of a Subarray
https://leetcode.com/problems/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:
不断查询数组中[i, j]范围内元素全部异或后的值。不改变数据结构内的值时查询范围用presum思想:res[0:j]去掉res[0:i-1]。XOR满足自己和自己相XOR为0,因此让prexors[j] ^ prexors[i - 1]就能把[0:i-1]从中去除。
Last updated
Was this helpful?