Choreography
Time limit0.5sMemory limit1024 MB
Apply cyclic shifts, pair swaps, and permutation moves to a line of dancers, then report where a given dancer stands after each prefix of moves.
- Level
Hard8 of 10
- Topics
- Array, Simulation, Math
- Solved
- No attempts yet
Problem
The Hungarian National Dance Ensemble is practicing a new choreography. There are dancers numbered from to , where is even.
At practice, the choreographer first lines up the dancers. Positions are numbered from to , and at the start, position is occupied by dancer .
After the line is formed, the choreographer calls a sequence of moves. Each move finishes before the next one begins. There are four types.
-
Every dancer moves positions to the right cyclically, where . For each from to , the dancer at position moves to position . For each from to , the dancer at position moves to position .
-
Every dancer moves positions to the left cyclically, where . For each from to , the dancer at position moves to position . For each from to , the dancer at position moves to position .
-
For each from to , the dancers at positions and swap places.
-
Suppose position () is occupied by dancer before this move. For each from to , dancer moves to position .
The dancers occupy distinct positions after every move.
The choreographer plans a sequence of moves and adds them one at a time. Before adding the next move, he sometimes asks which position a given dancer occupies after all moves added so far. Simulate the planned moves and answer these questions.
Constraints
- for each with
- for each and with
- Time limit: 500 ms. Memory limit: 1024 MB.