#P3285. [SCOI2014] 方伯伯的OJ
[SCOI2014] 方伯伯的OJ
Description
Uncle Fang is building his OJ. Now he is handling the user ranking problem on the OJ. There are registered users on the OJ, numbered , and initially they are ranked in ascending order of their IDs.
Depending on his mood, Uncle Fang performs the following four operations to modify users’ ranks and IDs:
- Operation format means: change the user whose ID is to have ID , while keeping their rank unchanged. After this operation, output that user’s position in the queue. It is guaranteed that appears in the queue, and is an ID not currently present in the ranking.
- Operation format means: move the user whose ID is to the first position. After this operation, output the rank of user before the move.
- Operation format means: move the user whose ID is to the last position. After this operation, output the rank of user before the move.
- Operation format means: query the ID of the user whose current rank is . After this operation, output that user’s ID.
To prevent others from snooping on his work, Uncle Fang encrypts his operations by changing the four formats to:
- ;
- ;
- ;
- ;
- where is the output of the previous operation, and initially .
Example: if the previous operation’s output is , and this operation’s input is , since the input is encrypted, the operation you should process is .
You have intercepted all of Uncle Fang’s operations. Please produce the results.
Input Format
The first line contains two integers and , representing the initial number of users and the number of operations. Then follow lines, each containing one query in the formats described above.
Output Format
Output lines. The integer on the -th line is the output of the -th operation.
10 10
1 2 11
3 13
2 5
3 7
2 8
2 10
2 11
3 14
2 18
4 9
2
2
2
4
3
5
5
7
8
11
Hint
For of the testdata, , .
It is guaranteed that for all operations , already appears in the queue. For all operations , , and does not appear in the queue.
For all operations , it is guaranteed that .
Translated by ChatGPT 5
京公网安备 11011102002149号