QOJ.ac

QOJ

时间限制: 3 s 内存限制: 2048 MB 总分: 100

#7660. 研究荷叶图案上的青蛙行为

统计

最近,生物学家 Ina 在池塘的荷叶上发现了一种新的青蛙。她观察了一段时间,发现这些青蛙非常有领地意识,因为它们避免与其他青蛙共用一片荷叶。此外,它们似乎很懒,不常移动;如果移动,它们总是跳到最近的空荷叶上。

为了证实她关于青蛙移动模式的假设,Ina 在实验室的水池中放置了大量荷叶,并将它们排成一条直线。由于青蛙具有趋光性,她通过在直线的一端放置一盏明灯进一步简化了测试设置。这样,青蛙总是会向一个方向(朝向光源)跳跃。

当然,Ina 现在可以将一些青蛙放在荷叶上,整天坐着观察它们跳来跳去。但由于青蛙移动得非常少,收集足够的数据需要很长时间。

因此,她给每只青蛙都贴上了一个微型设备,可以记录该青蛙的所有跳跃。这样,她就可以把青蛙放在荷叶上,让它们独处几个小时,然后再回来收集数据。不幸的是,这些设备必须做得非常小,以至于没有空间安装位置跟踪系统;相反,这些设备只能记录跳跃的时间戳。

但是,如果青蛙的移动模式正如 Ina 所想的那样受到限制,那么仅凭初始位置和记录的跳跃时间戳,是否一定能重构出青蛙的个体移动轨迹呢?

输入格式

输入包含: 一行一个整数 $n$ ($1 \le n \le 2 \cdot 10^5$),表示青蛙的数量。 一行 $n$ 个整数 $x_1, \dots, x_n$ ($1 \le x_i \le 10^6$),表示第 $i$ 只青蛙最初所在的荷叶编号。荷叶从 1 开始依次编号。保证初始位置严格递增,即 $x_1 < x_2 < \dots < x_n$。 一行一个整数 $q$ ($1 \le q \le 2 \cdot 10^5$),表示记录的跳跃次数。 $q$ 行,每行包含一个整数 $i$ ($1 \le i \le n$),表示第 $i$ 只青蛙跳跃了。跳跃按时间顺序给出,你可以假设一只青蛙在下一次跳跃开始前已经落地。青蛙总是跳到编号更大的最近的空荷叶上,你可以假设这样的荷叶总是存在的。

输出格式

对于每次跳跃,输出青蛙落地的荷叶编号。

样例

样例输入 1

5
1 2 3 5 7
3
1
2
4

样例输出 1

4
6
8

样例输入 2

5
1 2 3 5 7
4
1
1
1
1

样例输出 2

4
6
8
9

说明

图 I.1:第一个样例的示意图。荷叶从左到右编号,从 1 开始。

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.