#P10258. Bit Flipping Transformation
Bit Flipping Transformation
Bit Flipping Transformation
Given two sets of numbers A and B, each containing N integers, you are allowed to perform operations on A in order to transform it into B.
In one operation, you can choose any element from A and flip one arbitrary bit in its binary representation. The resulting number must be different from its original value. For example, the number \(5\) is represented as \(0101_2\) and can be changed to \(1101_2 = 13\), \(0001_2 = 1\), \(0111_2 = 7\), or \(0100_2 = 4\) by flipping exactly one bit.
Your task is to determine a sequence of operations such that, after all operations, the multiset A is equal to B (two multisets are equal if every element in one appears with the same frequency in the other). The number of operations does not need to be minimal, but the sequence must obey the rules above.
Note: Bit positions are numbered starting from 0 (with 0 being the least significant bit).
inputFormat
The input consists of three lines:
- The first line contains an integer \(N\) (\(1 \leq N \leq 10^5\)).
- The second line contains \(N\) space-separated integers representing the set A.
- The third line contains \(N\) space-separated integers representing the set B.
outputFormat
Output the sequence of operations as follows:
- On the first line, output an integer \(K\) representing the number of operations.
- Then output \(K\) lines, each containing two space-separated integers:
- An index \(i\) (1-indexed) specifying which element in A is modified.
- A bit position \(p\) (0-indexed) indicating which bit is flipped.
sample
3
5 2 7
7 3 7
2
1 1
2 0
</p>