3277. Maximum XOR Score Subarray Queries Hard

@problem@discussion
#Array#Dynamic Programming



1/**
2 * [3277] Maximum XOR Score Subarray Queries
3 *
4 * You are given an array nums of n integers, and a 2D integer array queries of size q, where queries[i] = [li, ri].
5 * For each query, you must find the maximum XOR score of any <span data-keyword="subarray">subarray</span> of nums[li..ri].
6 * The XOR score of an array a is found by repeatedly applying the following operations on a so that only one element remains, that is the score:
7 * 
8 * 	Simultaneously replace a[i] with a[i] XOR a[i + 1] for all indices i except the last one.
9 * 	Remove the last element of a.
10 * 
11 * Return an array answer of size q where answer[i] is the answer to query i.
12 *  
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">nums = [2,8,4,32,16,1], queries = [[0,2],[1,4],[0,5]]</span>
16 * Output: <span class="example-io">[12,60,60]</span>
17 * Explanation:
18 * In the first query, nums[0..2] has 6 subarrays [2], [8], [4], [2, 8], [8, 4], and [2, 8, 4] each with a respective XOR score of 2, 8, 4, 10, 12, and 6. The answer for the query is 12, the largest of all XOR scores.
19 * In the second query, the subarray of nums[1..4] with the largest XOR score is nums[1..4] with a score of 60.
20 * In the third query, the subarray of nums[0..5] with the largest XOR score is nums[1..4] with a score of 60.
21 * </div>
22 * <strong class="example">Example 2:
23 * <div class="example-block">
24 * Input: <span class="example-io">nums = [0,7,3,2,8,5,1], queries = [[0,3],[1,5],[2,4],[2,6],[5,6]]</span>
25 * Output: <span class="example-io">[7,14,11,14,5]</span>
26 * Explanation:
27 * <table height="70" width="472">
28 * 	<thead>
29 * 		<tr>
30 * 			<th>Index</th>
31 * 			<th>nums[li..ri]</th>
32 * 			<th>Maximum XOR Score Subarray</th>
33 * 			<th>Maximum Subarray XOR Score</th>
34 * 		</tr>
35 * 	</thead>
36 * 	<tbody>
37 * 		<tr>
38 * 			<td>0</td>
39 * 			<td>[0, 7, 3, 2]</td>
40 * 			<td>[7]</td>
41 * 			<td>7</td>
42 * 		</tr>
43 * 		<tr>
44 * 			<td>1</td>
45 * 			<td>[7, 3, 2, 8, 5]</td>
46 * 			<td>[7, 3, 2, 8]</td>
47 * 			<td>14</td>
48 * 		</tr>
49 * 		<tr>
50 * 			<td>2</td>
51 * 			<td>[3, 2, 8]</td>
52 * 			<td>[3, 2, 8]</td>
53 * 			<td>11</td>
54 * 		</tr>
55 * 		<tr>
56 * 			<td>3</td>
57 * 			<td>[3, 2, 8, 5, 1]</td>
58 * 			<td>[2, 8, 5, 1]</td>
59 * 			<td>14</td>
60 * 		</tr>
61 * 		<tr>
62 * 			<td>4</td>
63 * 			<td>[5, 1]</td>
64 * 			<td>[5]</td>
65 * 			<td>5</td>
66 * 		</tr>
67 * 	</tbody>
68 * </table>
69 * </div>
70 *  
71 * Constraints:
72 * 
73 * 	1 <= n == nums.length <= 2000
74 * 	0 <= nums[i] <= 2^31 - 1
75 * 	1 <= q == queries.length <= 10^5
76 * 	queries[i].length == 2 
77 * 	queries[i] = [li, ri]
78 * 	0 <= li <= ri <= n - 1
79 * 
80 */
81pub struct Solution {}
82
83// problem: https://leetcode.com/problems/maximum-xor-score-subarray-queries/
84// discuss: https://leetcode.com/problems/maximum-xor-score-subarray-queries/discuss/?currentPage=1&orderBy=most_votes&query=
85
86// submission codes start here
87
88impl Solution {
89    pub fn maximum_subarray_xor(nums: Vec<i32>, queries: Vec<Vec<i32>>) -> Vec<i32> {
90        vec![]
91    }
92}
93
94// submission codes end
95
96#[cfg(test)]
97mod tests {
98    use super::*;
99
100    #[test]
101    fn test_3277() {
102    }
103}
104


Back
© 2025 bowen.ge All Rights Reserved.