Rotate
Time limit1sMemory limit128 MB
Reverse a sequence of operations: first undo a rotation of each block of K, then undo a rotation of the whole sequence, recovering the original array.
- Level
Medium4 of 10
- Topics
- Implementation, Simulation, Array
- Solved
- No attempts yet
Problem
Sang-geun and Jeong-in invented a new game called Rotate.
First, Jeong-in thinks of a sequence of length . He then splits the sequence into sections that each hold numbers ( divides ). The first section holds the first numbers of the sequence, the second section holds the next numbers, and the remaining sections are filled the same way.
Jeong-in may apply the following two operations to the sequence.
- Rotate every section to the left or right by positions.
- Rotate the entire sequence to the left or right by positions.
Because operation 2 acts on the whole sequence, it may change which numbers belong to each section.
Jeong-in applies these operations to his sequence in order and then shows the final sequence to Sang-geun. Given the final sequence and the operations Jeong-in applied, in order, write a program that recovers the sequence Jeong-in originally thought of.
Input
The first line contains the length of the sequence , the section size , and the number of operations Jeong-in applied (, and divides ).
Each of the next lines describes one operation, in order. Each line contains an integer () indicating the operation type, followed by an integer () indicating how far to rotate. A negative rotates to the left and a positive rotates to the right.
The last line contains the final sequence after all operations have been applied, separated by spaces.
Output
Print the sequence Jeong-in originally thought of on the first line, separated by spaces.