Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3653 - XOR After Range Multiplication Queries I.

    Medium

    You are given an integer array nums of length n and a 2D integer array queries of size q, where <code>queriesi = l<sub>i</sub>, r<sub>i</sub>, k<sub>i</sub>, v<sub>i</sub></code>.

    For each query, you must apply the following operations in order:

    • Set <code>idx = l<sub>i</sub></code>.

    • While <code>idx <= r<sub>i</sub></code>:

    Return the bitwise XOR of all elements in nums after processing all queries.

    Example 1:

    Input: nums = 1,1,1, queries = [0,2,1,4]

    Output: 4

    Explanation:

    • A single query [0, 2, 1, 4] multiplies every element from index 0 through index 2 by 4.

    • The array changes from [1, 1, 1] to [4, 4, 4].

    • The XOR of all elements is 4 ^ 4 ^ 4 = 4.

    Example 2:

    Input: nums = 2,3,1,5,4, queries = [1,4,2,3,0,2,1,2]

    Output: 31

    Explanation:

    • The first query [1, 4, 2, 3] multiplies the elements at indices 1 and 3 by 3, transforming the array to [2, 9, 1, 15, 4].

    • The second query [0, 2, 1, 2] multiplies the elements at indices 0, 1, and 2 by 2, resulting in [4, 18, 2, 15, 4].

    • Finally, the XOR of all elements is 4 ^ 18 ^ 2 ^ 15 ^ 4 = 31.

    Constraints:

    • <code>1 <= n == nums.length <= 10<sup>3</sup></code>

    • <code>1 <= numsi<= 10<sup>9</sup></code>

    • <code>1 <= q == queries.length <= 10<sup>3</sup></code>

    • <code>queriesi = l<sub>i</sub>, r<sub>i</sub>, k<sub>i</sub>, v<sub>i</sub></code>

    • <code>0 <= l<sub>i</sub><= r<sub>i</sub>< n</code>

    • <code>1 <= k<sub>i</sub><= n</code>

    • <code>1 <= v<sub>i</sub><= 10<sup>5</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer xorAfterQueries(IntArray nums, Array<IntArray> queries)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait