QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 512 MB Points totaux : 100 Hackable ✓

#7072. 照片

Statistiques

毕业季临近,是时候拍摄纪念照了。

Bob 的班级里有 $n$ 名学生,每名学生都有一个从 $1$ 到 $n$ 的唯一学号,其中学号为 $i$ 的学生身高为 $h_i$。他们想在校门口以及另外 $q$ 个值得纪念的地方拍照。对于每个地点,学生们会按已知的顺序到达。为了增加个人参与度,每当一名学生到达时,他们就会拍一张新照片,因此在一个地点总共会拍 $n$ 张照片。在完成该地点的所有 $n$ 张照片后,学生们会回到宿舍,并为下一个地点安排新的时间。

为了使队列有序,每次拍新照片时,学生们必须按学号升序排列。照片的“有序度”(orderliness)定义为行中每两个相邻学生身高差的平方和。你的任务是计算在每个地点拍摄的 $n$ 张照片的有序度之和。

输入格式

第一行包含两个整数 $n$ 和 $q$ ($1 \le n \le 10^5, 0 \le q \le 100$),分别表示学生人数和值得纪念的地点数量。

第二行包含 $n$ 个整数,表示学生的身高,其中第 $i$ 个数为 $h_i$ ($1 \le h_i \le 10^4$)。

第三行包含 $n$ 个互不相同的整数 $p_1, p_2, \dots, p_n$,范围在 $1$ 到 $n$ 之间,表示在校门口学生到达的顺序。

接下来的 $q$ 行中,第 $i$ 行包含一个整数 $k$ ($0 \le k \le 10^9$),表示第 $(i+1)$ 个地点的学生到达顺序是在前一个地点的顺序基础上,向左循环移动 $(k + \text{lastans})$ 次得到的,其中 $\text{lastans}$ 是在第 $i$ 个地点拍摄的 $n$ 张照片的有序度之和。

注意:顺序 $p_1, p_2, \dots, p_{n-1}, p_n$ 向左循环移动一次后变为 $p_2, p_3, \dots, p_n, p_1$。

输出格式

输出 $(q + 1)$ 行,其中第 $i$ 行包含一个整数,表示在第 $i$ 个地点拍摄的 $n$ 张照片的有序度之和。

样例

输入 1

5 4
1 2 3 4 5
1 2 3 4 5
6
6
8
10

输出 1

10
10
13
21
36

说明

对于样例,每个地点学生到达的顺序如下: $[1, 2, 3, 4, 5] \to [2, 3, 4, 5, 1] \to [3, 4, 5, 1, 2] \to [4, 5, 1, 2, 3] \to [5, 1, 2, 3, 4]$。

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.