Processor Design
Time limit1sMemory limit128 MB
Reconstruct lexicographically smallest initial 32-bit register values consistent with a sequence of bit-rotation and XOR-output commands, using union-find over bits with XOR relations.
- Level
Medium6 of 10
- Topics
- Union-find, Bit manipulation, Greedy
- Solved
- No attempts yet
Problem
Boseop designed a small processor for a computer architecture and logic assignment. The processor has N registers numbered from 1 to N. Each register stores an unsigned 32-bit integer in the usual binary representation, from 0 to 2^32 - 1. The processor supports the following two commands.
The processor has already been built, but it has no command for directly reading the value stored in a register. Therefore, the only way to determine a register value is by using commands 1 and 2. Given the order of commands that were executed and every output produced by command 2, reconstruct the values initially stored in all registers.
If multiple initial register sequences are possible, output the lexicographically smallest one.
Input
The first line contains the number of registers N and the number of commands E executed by the processor. (2 <= N <= 100,000, 1 <= E <= 100,000)
Each command is then given in order. Every command is valid and satisfies 1 <= K, L <= N and 0 <= M < 32. Whenever a command of type 2 is given, the next line contains the decimal value output on the system bus.
Output
Print the initial values of the N registers from register 1 to register N, separated by spaces.
If no initial register sequence can produce the given outputs, print -1.