1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/子数组异或查询 [xor-queries-of-a-subarray].html
2022-03-29 12:43:11 +08:00

45 lines
1.5 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>有一个正整数数组 <code>arr</code>,现给你一个对应的查询数组 <code>queries</code>,其中 <code>queries[i] = [L<sub>i, </sub>R<sub>i</sub>]</code></p>
<p>对于每个查询 <code>i</code>,请你计算从 <code>L<sub>i</sub></code> 到 <code>R<sub>i</sub></code> 的 <strong>XOR</strong> 值(即 <code>arr[L<sub>i</sub>] <strong>xor</strong> arr[L<sub>i</sub>+1] <strong>xor</strong> ... <strong>xor</strong> arr[R<sub>i</sub>]</code>)作为本次查询的结果。</p>
<p>并返回一个包含给定查询 <code>queries</code> 所有结果的数组。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]]
<strong>输出:</strong>[2,7,14,8]
<strong>解释:</strong>
数组中元素的二进制表示形式是:
1 = 0001
3 = 0011
4 = 0100
8 = 1000
查询的 XOR 值为:
[0,1] = 1 xor 3 = 2
[1,2] = 3 xor 4 = 7
[0,3] = 1 xor 3 xor 4 xor 8 = 14
[3,3] = 8
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]]
<strong>输出:</strong>[8,0,4,4]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= arr.length <= 3 * 10^4</code></li>
<li><code>1 <= arr[i] <= 10^9</code></li>
<li><code>1 <= queries.length <= 3 * 10^4</code></li>
<li><code>queries[i].length == 2</code></li>
<li><code>0 <= queries[i][0] <= queries[i][1] < arr.length</code></li>
</ul>