QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#8538. 无限冒险

Statistics

注意:本题的内存限制为 512MB,是默认限制的两倍。

Bessie 计划在一个拥有 $N$ ($1\leq N \leq 10^5$) 个城市的国度里进行一场无限的冒险。每个城市 $i$ 都有一个传送门,以及一个循环周期 $T_i$。所有的 $T_i$ 均为 $2$ 的幂,且满足 $T_1 + \cdots + T_N \leq 10^5$。如果你在第 $t$ 天进入城市 $i$ 的传送门,你将立即从城市 $c_{i, t\bmod{T_i}}$ 的传送门出来。

Bessie 有 $Q$ ($1\leq Q \leq 5\cdot 10^4$) 个旅行计划,每个计划由一个三元组 $(v, t, \Delta)$ 组成。在每个计划中,她将从第 $t$ 天在城市 $v$ 出发。随后她会进行 $\Delta$ 次操作:她会进入当前城市的传送门,然后等待一天。对于她的每一个计划,她都想知道最终会停留在哪个城市。

输入

第一行包含两个空格分隔的整数:$N$(城市数量)和 $Q$(查询数量)。

第二行包含 $N$ 个空格分隔的整数:$T_1, T_2, \ldots, T_N$($1\leq T_i$,$T_i$ 为 $2$ 的幂,且 $T_1 + \cdots + T_N \leq 10^5$)。

对于 $i = 1, 2, \ldots, N$,第 $i+2$ 行包含 $T_i$ 个空格分隔的正整数,即 $c_{i, 0}, \ldots, c_{i, T_i-1}$ ($1\leq c_{i, t} \leq N$)。

对于 $j = 1, 2, \ldots, Q$,第 $j+N+2$ 行包含三个空格分隔的正整数 $v_j, t_j, \Delta_j$ ($1\leq v_j \leq N$, $1\leq t_j \leq 10^{18}$, $1\leq \Delta_j \leq 10^{18}$),表示第 $j$ 个查询。

输出

输出 $Q$ 行。第 $j$ 行必须包含第 $j$ 个查询的答案。

样例

输入格式 1

5 4
1 2 1 2 8
2
3 4
4
2 3
5 5 5 5 5 1 5 5
2 4 3
3 3 6
5 3 2
5 3 7

输出格式 1

2
2
5
4

说明

Bessie 的前三次冒险过程如下:

  • 在第一次冒险中,她从第 $4$ 天的城市 $2$ 出发,到达第 $5$ 天的城市 $3$,到达第 $6$ 天的城市 $4$,到达第 $7$ 天的城市 $2$。
  • 在第二次冒险中,她从第 $3$ 天的城市 $3$ 出发,到达第 $4$ 天的城市 $4$,到达第 $5$ 天的城市 $2$,到达第 $6$ 天的城市 $4$,到达第 $7$ 天的城市 $2$,到达第 $8$ 天的城市 $4$,到达第 $9$ 天的城市 $2$。
  • 在第三次冒险中,她从第 $3$ 天的城市 $5$ 出发,到达第 $4$ 天的城市 $5$,到达第 $5$ 天的城市 $5$。

输入格式 2

5 5
1 2 1 2 8
2
3 4
4
2 3
5 5 5 5 5 1 5 5
2 4 3
3 2 6
5 3 2
5 3 7
5 3 1000000000000000000

输出格式 2

2
3
5
4
2

SCORING

  • 输入 3:$\Delta_j \leq 2\cdot 10^2$。
  • 输入 4-5:$N, \sum T_j\leq 2\cdot 10^3$。
  • 输入 6-8:$N, \sum T_j\leq 10^4$。
  • 输入 9-18:无额外限制。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#118EditorialOpen题解dXqwq2025-12-12 23:07:44View

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.