Fast Debugger
Time limit1sMemory limit2048 MB
Given a program of bitwise instructions on four 8-bit registers with nested repeat blocks, find the register values after the first k instructions.
- Level
Hard8 of 10
- Topics
- Bit manipulation, Divide and conquer, Simulation
- Solved
- No attempts yet
Statement
Recently you received an old computer. It has an 8-bit CPU with four registers, ax, bx, cx, and dx, and supports only a few simple instructions. This guide is for readers who are not familiar with assembly language.
Each register is 8 bits, so its value is an integer in .
The CPU supports three bitwise operations: or, and, and xor. Each operation has two kinds of instructions.
Type 1 takes two registers, written as or r1 r2, where r1 and r2 are each one of ax, bx, cx, or dx. The two may be the same register. It sets r1 to the bitwise or of r1 and r2. The and and xor instructions are written as and r1 r2 and xor r1 r2.
Type 2 takes one immediate operand, written as ori r imm, where r is a register and imm is a constant in given in the instruction. It sets r to the bitwise or of r and imm. The and and xor versions are andi r imm and xori r imm.
The assembler supports a simple loop. When it reads a repeat m statement, it runs the contents of the repeat block a total of times. The format is:
repeat m
<repeat block>
end
Here is a constant in . The <repeat block> has one or more statements, each either a bitwise instruction or a nested repeat-end statement.
You are writing a simulator for this CPU. You receive a valid program and queries. Each query gives five integers . At the start, ax , bx , cx , and dx . Output the values of the four registers after the program executes bitwise instructions.
Input
The first line contains two integers and (, ), the number of instructions and the number of queries.
The next lines each contain one instruction in the format described above.
Each of the next lines contains five integers (, ). The program is guaranteed not to terminate before it executes bitwise instructions.
Output
Print lines. The -th line contains four integers , the values of ax, bx, cx, and dx after the program executes bitwise instructions.