Rotating the basket order
InterviewTime limit1sMemory limit256 MB
Perform M given segment rotations on baskets numbered 1 to N and print the final left-to-right order.
- Level
Easy2 of 10
- Topics
- Simulation, Array
- Solved
- No attempts yet
Problem
Dohyun has baskets, and the baskets are numbered 1 through in order. The baskets stand in one row. The leftmost basket is at position 1, the next one at position 2, and so on up to position at the right end.
Dohyun rotates the basket order times. For each rotation he picks the range to rotate, then picks one basket inside that range as the pivot. If the ends of the chosen range are and and the pivot sits at position , then the baskets that stood in the order end up in the order .
Given the rotations, write a program that performs all of them and prints the number written on each basket, starting from the leftmost one.
Input
The first line contains () and ().
Each of the next lines contains one rotation as three integers , , . It means the order of the baskets from position to position counted from the left is rotated, and the pivot is the basket at position . ()
Dohyun applies the rotations in the order they are given.
Output
After all rotations, print the number written on each basket from the leftmost one, on one line, separated by single spaces.