Cubic Art
Time limit1sMemory limit1024 MB
Given a cube state and a move sequence, apply point updates that replace one move and print the resulting cube state after each update.
- Level
Medium7 of 10
- Topics
- Segment tree, Simulation, Matrix, Implementation
- Solved
- No attempts yet
Problem
Modern art is unpredictable. While tidying his room, Bob found his old Rubik's cube. Then the moment came. He closed his eyes, listened to his inner voice, made a few moves (up to 65000 of them), and the masterpiece was nearly complete. The final state was not to his liking, though. He realized that he had done some of the moves wrong. If only he could go back in time and change them.
All he needs now is a few changes (again, up to 65000 of them). Each change replaces one move with some other move. Bob wants to see what each change does, but repeating the entire sequence of moves over and over is tedious.
You are given the initial state of Bob's cube. The cube is not necessarily solved in its initial state. You are also given the original sequence of moves Bob performed.
Finally, you are given a sequence of changes. Each change has the form "change the -th move into this new move". For each change, print the state of the cube at the end of the entire sequence of moves.
The changes are permanent. The second change applies to the sequence of moves that already carries the first change, not to the original sequence.
Input
The colors of the cube are A, B, C, D, E, F. The middle squares of the faces do not move while you play with the cube, so A is always the color of the center of the top face, B, C, D, E are the centers of the side faces (in order), and F is the center of the bottom face. The surface of the cube unfolds into the following form.
???
?A?
???
????????????
?B??C??D??E?
????????????
???
?F?
???
The top face is attached to the upper edge of the B face, the bottom face is attached to the lower edge of the B face, and the middle band goes once around the cube in the order B, C, D, E.
The first 9 lines of the input contain the starting state of the cube in the form above. The centers of the six faces are colored as shown.
The next line has two integers and . is the number of moves and is the number of subsequent changes.
The next lines describe Bob's original moves. They have the form " ", where is the color of the center of the rotated face and is for a clockwise move and for a counterclockwise move. The direction is the one you see when you look at that face from outside the cube.
The last lines describe the changes, in order. Each one has the form " ", where is the 1-based index of the move that is being replaced and describes the new move.
In all test cases, and .
Output
Let be the sequence of moves obtained from the original sequence by applying the first changes. For each between and , inclusive, print 9 lines: the final state of the cube obtained by starting in the initial configuration and performing the sequence of moves . Use the same format as in the input.
Hint
In the first example the original moves cancel each other out, so the cube is back in its initial state at the end of the original sequence. After all four changes of that example are applied, the resulting sequence of moves changes the color of every square except the centers of the six faces.