#P13702. [NWERC 2023] Chair Dance
[NWERC 2023] Chair Dance
题目描述
In a deterministic version of Musical Chairs, there are chairs placed in a circle. The chairs are numbered from to in clockwise order. Initially, the th player sits on the th chair. During the game, the game master gives commands to all players at once.
:::align{center} A family playing Musical Chairs. CC BY-SA 3.0 by Artaxerxes on Wikimedia Commons :::
The first type of command tells each player to move chairs farther in clockwise order, so they must move from chair to chair .
The second type of command tells each player to move from chair to chair . Both these calculations are done modulo , where a remainder of corresponds to chair .
If two or more people want to move to the same chair, then the player needing to travel the least in clockwise direction to reach the chair gets to take the seat, and the other players trying to reach the same chair are out of the game. This is illustrated in Figure C.1, where the larger circles represent the chairs and their numbers are written on their inside. The smaller circles represent the players. The next command () tells player (now on seat ) and player (now on seat ) to move to chair . However, since player needs to travel less, this player gets to take the seat. Note that the other players will also move to some other chairs, but this is omitted from the figure for the sake of readability.
:::align{center} Figure C.1: Illustration of Sample Input 1 at the fourth command, where players and need to move to chair . Because player needs to travel less in clockwise direction, this player gets to take the seat. :::
The jury wasted most of their free time designing this game and now need to go back to work. Fortunately, the game is deterministic, so you can play the game without the help of the jury.
You do not need to know the original game, but you can try to play it after the contest is over.
输入格式
The input consists of:
-
One line with two integers and (), the number of chairs and the number of commands.
-
lines, each containing one of three command types:
- "": The player on chair moves to chair .
- "": The player on chair moves to chair .
- "": Tell us the number of the player on chair .
All of the values will satisfy .
输出格式
For each command of type '', output the number of the player on the requested chair. If the chair is currently empty, output instead.
12 10
? 12
+ 1
? 12
* 10
? 2
* 5
? 2
* 6
? 1
? 12
12
11
10
6
-1
11
32 11
* 6
? 8
* 6
+ 31
* 28
? 4
+ 1
* 2
+ 1
* 3
? 1
28
32
32