XOR After Range Multiplication Queries I

You are given an integer array nums of length n and a 2D integer array queries of size q, where queries[i] = [li, ri, ki, vi].

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

  • Set idx = li.
  • While idx <= ri:
  • Update nums[idx] = (nums[idx] * vi) % (10^9 + 7).
  • Set idx += ki.

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

Example 1
Inputnums = [1,1,1], queries = [[0,2,1,4]]
Output4
A single query multiplies every element by 4, changing nums to [4, 4, 4], whose XOR is 4.
Example 2
Inputnums = [2,3,1,5,4], queries = [[1,4,2,3],[0,2,1,2]]
Output31
After applying both queries, nums becomes [4, 18, 2, 15, 4], and 4 ^ 18 ^ 2 ^ 15 ^ 4 = 31.

Constraints

  • 1 <= n == nums.length <= 10^3
  • 1 <= nums[i] <= 10^9
  • 1 <= q == queries.length <= 10^3
  • queries[i] = [li, ri, ki, vi]
  • 0 <= li <= ri < n
  • 1 <= ki <= n
  • 1 <= vi <= 10^5

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate