QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 100 MB مجموع النقاط: 100

#6976. 挂衣架

الإحصائيات

挂衣架由 $n$ 层相互连接的杆组成。第 $i$ 层(其中 $i \in \{0, 1, \dots, n-1\}$)包含 $2^i$ 根杆。第 0 层杆的中点固定在墙上。在所有其他层中,第 $j$ 根杆(其中 $j \in 1, \dots, 2^i$)的中点固定在上一层第 $\lceil j/2 \rceil$ 根杆的左端点(如果 $j$ 为奇数)或右端点(如果 $j$ 为偶数)。在最后一层,每根杆的两个端点上各有一个挂钩,用于悬挂外套。挂钩从左到右编号为 $1$ 到 $2^n$。

例如,$n=3$ 时的挂衣架结构如下:

Mojca 想把她所有的外套都挂在衣架上。每件外套的重量恰好为 $1$ 个单位。为了避免损坏脆弱的结构,她必须按照一定的顺序悬挂外套,使得任意给定杆的左端点上的总重量与右端点上的总重量之差为 $0$ 或 $1$(即 $w_l - w_r \in \{0, 1\}$)。(根据物理定律,差值也可以是 $-1$,但 Mojca 觉得向右倾斜的衣架非常难看。)杆非常细,其重量可以忽略不计。

Mojca 向你寻求帮助。请编写一个程序,读取整数 $n$ 和整数 $k$,并输出 Mojca 悬挂第 $k$ 件外套时所使用的挂钩编号(对 $10^9 + 7$ 取模)。

输入格式

输入包含一行,包含两个整数 $n$ 和 $k$,中间用空格隔开。

输出格式

输出第 $k$ 步所使用的挂钩编号(对 $10^9 + 7$ 取模)。

数据范围

  • $n \in [1, 10^6]$
  • $k \in [1, \min\{2^n, 10^{18}\}]$

子任务

  • 20 分:$n \in [1, 10]$
  • 20 分:$n \in [1, 20]$
  • 60 分:无附加限制

样例

样例输入 1

3 2

样例输出 1

5

说明 1

在这种情况下,挂钩的使用顺序为:1, 5, 3, 7, 2, 6, 4, 8。因此,在第二步中,Mojca 必须将外套挂在编号为 5 的挂钩上。

样例输入 2

5 10

样例输出 2

19

说明 2

此处,挂钩的顺序为 1, 17, 9, 25, 5, 21, 13, 29, 3, 19 等。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.