1310. XOR Queries of a Subarray Medium

@problem@discussion
#Array#Bit Manipulation#Prefix Sum



1/**
2 * [1310] XOR Queries of a Subarray
3 *
4 * You are given an array arr of positive integers. You are also given the array queries where queries[i] = [lefti, righti].
5 * For each query i compute the XOR of elements from lefti to righti (that is, arr[lefti] XOR arr[lefti + 1] XOR ... XOR arr[righti] ).
6 * Return an array answer where answer[i] is the answer to the i^th query.
7 *  
8 * Example 1:
9 * 
10 * Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]]
11 * Output: [2,7,14,8] 
12 * Explanation: 
13 * The binary representation of the elements in the array are:
14 * 1 = 0001 
15 * 3 = 0011 
16 * 4 = 0100 
17 * 8 = 1000 
18 * The XOR values for queries are:
19 * [0,1] = 1 xor 3 = 2 
20 * [1,2] = 3 xor 4 = 7 
21 * [0,3] = 1 xor 3 xor 4 xor 8 = 14 
22 * [3,3] = 8
23 * 
24 * Example 2:
25 * 
26 * Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]]
27 * Output: [8,0,4,4]
28 * 
29 *  
30 * Constraints:
31 * 
32 * 	1 <= arr.length, queries.length <= 3 * 10^4
33 * 	1 <= arr[i] <= 10^9
34 * 	queries[i].length == 2
35 * 	0 <= lefti <= righti < arr.length
36 * 
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/xor-queries-of-a-subarray/
41// discuss: https://leetcode.com/problems/xor-queries-of-a-subarray/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46    pub fn xor_queries(arr: Vec<i32>, queries: Vec<Vec<i32>>) -> Vec<i32> {
47        vec![]
48    }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn test_1310() {
59    }
60}
61


Back
© 2025 bowen.ge All Rights Reserved.