XOR After Range Multiplication Queries II
Real-world version: Combining a Long Ledger After Stepped ScalingThe statement here is our own: the same inputs, outputs and technique.
A ledger holds entries nums. Each adjustment in queries is [l, r, k, v] and multiplies, modulo 10^9 + 7, the entries at positions l, l + k, l + 2k and onwards, as far as position r inclusive.
Both the ledger and the list of adjustments may run to a hundred thousand, so working every adjustment out entry by entry is far too slow.
Return the bitwise exclusive-or of the finished ledger.
Examples
Example 1
- Input
- nums = [1, 2, 4, 8, 16, 32], queries = [[1, 4, 2, 3]]
- Output
- 43
The single adjustment strides by two from position 1 and stops at position 4, so it reaches positions 1 and 3 only, tripling those two entries and leaving the rest as they were.
Example 2
- Input
- nums = [5, 9], queries = [[0, 1, 2, 3], [1, 1, 1, 4]]
- Output
- 43
The first adjustment strides by two from position 0, so it reaches position 0 alone and trebles the 5. The second multiplies position 1 by four.
Example 3
- Input
- nums = [6, 12, 18, 24, 30], queries = [[0, 4, 1, 1], [0, 4, 1, 1]]
- Output
- 30
Both adjustments multiply by one, so the ledger is untouched.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^9
- 1 <= queries.length <= 10^5
- queries[i].length == 4
- 0 <= queries[i][0] <= queries[i][1] <= nums.length - 1
- 1 <= queries[i][2] <= nums.length
- 1 <= queries[i][3] <= 10^5
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def xor_after_queries(nums: list[int], queries: list[list[int]]) -> int:public int xorAfterQueries(int[] nums, int[][] queries)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Count Subarrays With Majority Element IReal-world version: Stretches Carried by One CandidateMedium
- XOR After Range Multiplication Queries IReal-world version: Combining Meters After Stepped ScalingMedium
- Majority ElementReal-world version: Quorum Drift ValueEasy
- Find Pivot IndexReal-world version: Beam Balance StationEasy