#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 GG.

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 GG is set to 1.

Ironically, the hotel can accept more guests even though every room is filled:

  • If kk (k1k \geq 1) people arrive at the hotel, then for each room number xx, the guest in room xx moves to room x+kx+k. After that, the new guests fill all the rooms from 0 to k1k-1.
  • If infinitely many people arrive at the hotel, then for each room number xx, the guest in room xx moves to room 2x2x. 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:

  • 1 k\tt{1\ k} - If k1k \geq 1, then kk people arrive at the hotel. If k=0k = 0, then infinitely many people arrive at the hotel. Assign the group number GG to the new guests, and then increment GG by 1.
  • 2 g x\tt{2\ g\ x} - Find the xx-th smallest room number that contains a guest with the group number gg. Output it modulo 109+710^9 + 7, followed by a newline.
  • 3 x\tt{3\ x} - Output the group number of the guest in room xx, followed by a newline.

输入格式

In the first line, an integer QQ (1Q300,0001 \leq Q \leq 300,000) denoting the number of queries is given. Each of the next lines contains a query. All numbers in the queries are integers.

  • For the 1 k\tt{1\ k} queries, 0k1090 \leq k \leq 10^9.
  • For the 2 g x\tt{2\ g\ x} queries, g<Gg < G, 1x1091 \leq x \leq 10^9, and at least xx guests have the group number gg.
  • For the 3 x\tt{3\ x} queries, 0x1090 \leq x \leq 10^9.

输出格式

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.