Or Machine
Time limit4sMemory limit1024 MB
Run a cyclic program of bitwise-OR register assignments t times, with t up to 1e18, and print the final register values.
- Level
Medium7 of 10
- Topics
- Graph, Bit manipulation, Binary search, Simulation
- Solved
- No attempts yet
Problem
We are developing the Or Machine, a computer heavily optimized for a single operation: the | operator in C++.
The Or Machine has registers, each holding a nonnegative integer less than . We label them . A program is represented by a list of operations. Each operation is represented by a pair of integers , meaning that the machine should update with the bitwise OR of the values of and .
The Or Machine takes a program, the initial values of the registers, and a positive integer . When run, the program performs each operation in the program one by one. When the last operation is performed, it goes back to the first operation and repeats the process. The machine stops after performing exactly operations.
We want our machine to be much faster than general-purpose computers, and hardware optimization is probably not enough. Can you help us with some software optimization?
Input
The first line contains three integers, , , and , . is the length of the program.
The program is given on the next lines. Each line contains two integers and representing the pair of registers that participate in the given operation.
The final line contains integers, the initial values of the registers .
Output
Output integers on a single line, the values of the registers after operations.