#P14617. [2019 KAIST RUN Fall] Hilbert' s Hotel
[2019 KAIST RUN Fall] Hilbert' s Hotel
题目描述
Hilbert's hotel has infinitely many rooms, numbered 0, 1, 2, ... At most one guest occupies each room. Since people tend to check-in in groups, the hotel has a group counter variable .
Hilbert's hotel had a grand opening today. Soon after, infinitely many people arrived at once, filling every room in the hotel. All guests got the group number 0, and is set to 1.
Ironically, the hotel can accept more guests even though every room is filled:
- If () people arrive at the hotel, then for each room number , the guest in room moves to room . After that, the new guests fill all the rooms from 0 to .
- If infinitely many people arrive at the hotel, then for each room number , the guest in room moves to room . After that, the new guests fill all the rooms with odd numbers.
:::align{center}
:::
You have to write a program to process the following queries:
- - If , then people arrive at the hotel. If , then infinitely many people arrive at the hotel. Assign the group number to the new guests, and then increment by 1.
- - Find the -th smallest room number that contains a guest with the group number . Output it modulo , followed by a newline.
- - Output the group number of the guest in room , followed by a newline.
输入格式
In the first line, an integer () denoting the number of queries is given. Each of the next lines contains a query. All numbers in the queries are integers.
- For the queries, .
- For the queries, , , and at least guests have the group number .
- For the queries, .
输出格式
Process all queries and output as required. It is guaranteed that the output is not empty.
10
3 0
1 3
2 1 2
1 0
3 10
2 2 5
1 5
1 0
3 5
2 3 3
0
1
0
9
4
4
提示
If you know about cardinals, please assume that infinite refers only to countably infinite. If you don't know about it, then you don't have to worry.
京公网安备 11011102002149号