A range xor in two reads
transcript
Many deploys toggle many flags. A question asks about a range of deploys. Which flags are on?
Build prefix xors once. Start with zero. After the first mask, the prefix is five. After the second mask, it is six.
Ask for the deploys one to two. Read the prefix after them, and before them. Xor those two values together.
The prefix after is zero. The prefix before is five. Zero xor five is five. Five has two bits set. Two flags are on.
Both prefixes share the first deploys. Xor cancels anything that appears twice. Only the range remains.
The table has one extra entry. The range l to r reads P at r plus one. Reading P at r drops the last deploy.
A hundred thousand deploys and questions. Xoring each range directly takes ten billion steps. The table answers each in two reads.
Build the table once. Then xor two values. Full breakdown in the lecture.