Xor Segment Ledger
Preview mode. Log in to edit, run, submit, and save progress.
Xor Segment Ledger
A telemetry ledger stores non-negative integer readings in a line. The operations team processes two operation types. A report operation asks for the sum of readings on a 1-indexed interval. A mask operation applies bitwise XOR with a given value to every reading on a 1-indexed interval. For each batch, print every requested report in the order it appears. Input Format: The first line contains t. Each case contains n, then n readings, then q operations. Operation type 1 is written as 1 l r and asks for the interval sum. Operation type 2 is written as 2 l r x and applies value XOR x to every reading from l to r. Output Format: Print one line for each type 1 operation.
Examples
1 5 1 2 3 4 5 5 1 1 5 2 2 4 7 1 1 3 2 1 5 1 1 4 5
15
Explanation: The first report sums the original array. The next report happens after applying XOR 7 to positions 2 through 4. The final report reflects both XOR updates that occurred before it.
Approach hint
XOR with one bit flips how many values have that bit set.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.