mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 15:31:43 +08:00
62 lines
3.0 KiB
HTML
62 lines
3.0 KiB
HTML
<p>You are given an integer array <code>nums</code> of length <code>n</code> and a 2D integer array <code>queries</code> of size <code>q</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>, k<sub>i</sub>, v<sub>i</sub>]</code>.</p>
|
||
|
||
<p>For each query, you must apply the following operations in order:</p>
|
||
|
||
<ul>
|
||
<li>Set <code>idx = l<sub>i</sub></code>.</li>
|
||
<li>While <code>idx <= r<sub>i</sub></code>:
|
||
<ul>
|
||
<li>Update: <code>nums[idx] = (nums[idx] * v<sub>i</sub>) % (10<sup>9</sup> + 7)</code></li>
|
||
<li>Set <code>idx += k<sub>i</sub></code>.</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<p>Return the <strong>bitwise XOR</strong> of all elements in <code>nums</code> after processing all queries.</p>
|
||
|
||
<p> </p>
|
||
<p><strong class="example">Example 1:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>Input:</strong> <span class="example-io">nums = [1,1,1], queries = [[0,2,1,4]]</span></p>
|
||
|
||
<p><strong>Output:</strong> <span class="example-io">4</span></p>
|
||
|
||
<p><strong>Explanation:</strong></p>
|
||
|
||
<ul>
|
||
<li data-end="106" data-start="18">A single query <code data-end="44" data-start="33">[0, 2, 1, 4]</code> multiplies every element from index 0 through index 2 by 4.</li>
|
||
<li data-end="157" data-start="109">The array changes from <code data-end="141" data-start="132">[1, 1, 1]</code> to <code data-end="154" data-start="145">[4, 4, 4]</code>.</li>
|
||
<li data-end="205" data-start="160">The XOR of all elements is <code data-end="202" data-start="187">4 ^ 4 ^ 4 = 4</code>.</li>
|
||
</ul>
|
||
</div>
|
||
|
||
<p><strong class="example">Example 2:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>Input:</strong> <span class="example-io">nums = [2,3,1,5,4], queries = [[1,4,2,3],[0,2,1,2]]</span></p>
|
||
|
||
<p><strong>Output:</strong> <span class="example-io">31</span></p>
|
||
|
||
<p><strong>Explanation:</strong></p>
|
||
|
||
<ul>
|
||
<li data-end="350" data-start="230">The first query <code data-end="257" data-start="246">[1, 4, 2, 3]</code> multiplies the elements at indices 1 and 3 by 3, transforming the array to <code data-end="347" data-start="333">[2, 9, 1, 15, 4]</code>.</li>
|
||
<li data-end="466" data-start="353">The second query <code data-end="381" data-start="370">[0, 2, 1, 2]</code> multiplies the elements at indices 0, 1, and 2 by 2, resulting in <code data-end="463" data-start="448">[4, 18, 2, 15, 4]</code>.</li>
|
||
<li data-end="532" data-is-last-node="" data-start="469">Finally, the XOR of all elements is <code data-end="531" data-start="505">4 ^ 18 ^ 2 ^ 15 ^ 4 = 31</code>.<strong></strong></li>
|
||
</ul>
|
||
</div>
|
||
|
||
<p> </p>
|
||
<p><strong>Constraints:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= n == nums.length <= 10<sup>3</sup></code></li>
|
||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||
<li><code>1 <= q == queries.length <= 10<sup>3</sup></code></li>
|
||
<li><code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>, k<sub>i</sub>, v<sub>i</sub>]</code></li>
|
||
<li><code>0 <= l<sub>i</sub> <= r<sub>i</sub> < n</code></li>
|
||
<li><code>1 <= k<sub>i</sub> <= n</code></li>
|
||
<li><code>1 <= v<sub>i</sub> <= 10<sup>5</sup></code></li>
|
||
</ul>
|