| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 0.5 초 | 1024 MB | 21 | 9 | 8 | 47.059% |
The Hungarian National Dance Ensemble is practicing a new choreography. There are $N$ dancers in the ensemble, numbered from $0$ to $N - 1$, where $N$ is an even number.
At the practice sessions, the choreographer first lines up the dancers. The positions in the line are numbered from $0$ to $N - 1$, and position $i$ is occupied by dancer $P[i]$ at the start.
After the dancers line up, the choreographer asks them to perform a sequence of moves. Each move must be completed before they begin performing the next one. The dancers are practicing $4$ types of moves:
Note that the positions of the dancers are distinct at the end of each move.
Before the next session, the choreographer plans a sequence of $M$ moves for the ensemble to practice. He adds the moves to the sequence one by one. Sometimes, before adding the next move, he wonders which positions certain dancers will occupy right after performing every move that has been added to the sequence.
Your task is to simulate the dance moves planned by the choreographer and answer his questions about the positions of the dancers.
You should implement the following procedures:
void init(int N, int[] P)
void move_right(int K)
void move_left(int K)
void swap_places()
void move_around()
Procedures move_right, move_left, swap_places, and move_around are called for a total of $M$ times.
int get_position(int D)
Consider the following sequence of calls:
init(6, [5, 1, 4, 2, 0, 3])
There are $6$ dancers, and the initial order of the dancers is given by the array $[5, 1, 4, 2, 0, 3]$, that is, position $0$ is occupied by dancer $5$, position $1$ is occupied by dancer $1$, position $2$ is occupied by dancer $4$, and so on.
move_left(2)
Each dancer moves two places to the left cyclically. After the move, the order of the dancers becomes $[4, 2, 0, 3, 5, 1]$.
get_position(0)
This call asks the position of dancer $0$ after performing the first move. Dancer $0$ is standing at position $2$. Therefore, the procedure should return $2$.
swap_places()
After this move, the order of the dancers becomes $[2, 4, 3, 0, 1, 5]$.
move_around()
The new position of each dancer is determined as follows.
After this move, the order of the dancers becomes $[3, 4, 0, 2, 1, 5]$.
get_position(3)
Dancer $3$ is at position $0$ after performing every move so far. The procedure should return $0$.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 7 | Only moves of types 1 and 2 are performed. |
| 2 | 12 | $N \cdot (Q + M) ≤ 1\,000\,000$ |
| 3 | 10 | Only moves of type 4 are performed. |
| 4 | 14 | Only moves of types 3 and 4 are performed. |
| 5 | 28 | Only moves of types 1, 2, and 4 are performed. |
| 6 | 29 | No additional constraints. |
The sample grader reads the input in the following format:
The sample grader prints your answers in the following format:
get_positionC++17, C++20, C++17 (Clang), C++20 (Clang)