QOJ.ac

QOJ

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

#531. 游戏

الإحصائيات

Alice 和 Bob 正在玩以下游戏:

他们拥有一个包含 $N$ 个正整数的序列,这些整数的值小于或等于 $N$。序列中的元素从 $1$ 到 $N$ 编号。序列中可能存在相等的数字。游戏开始时会创建一个集合 $S$,其中包含序列的前 $P$ 个元素。注意,$S$ 可能是一个多重集(multiset),即它可能包含相等的元素。玩家轮流进行游戏,Alice 先手。每一步操作如下:

1) 当前轮到操作的玩家从集合 $S$ 中选择一个数字并将其取走,将其值加到他/她自己的得分中(初始时,两名玩家的得分均为 $0$)。 2) 序列中的下一个数字(如果还有剩余的话)会被加入到集合 $S$ 中(如果序列已经为空,则跳过此操作)。也就是说,在第一次从 $S$ 中取走数字后,索引为 $P+1$ 的数字被加入集合;在第二次取走后,索引为 $P+2$ 的数字被加入,以此类推。

游戏持续进行,直到集合 $S$ 变为空。我们假设每位玩家都会尽其所能最大化自己的得分。游戏的结果定义为 Alice 的得分减去 Bob 的得分。

任务

编写一个程序 game,处理给定初始序列下的 $K$ 场游戏。

输入格式

第一行包含两个用空格分隔的正整数 $N$ 和 $K$。

第二行包含 $N$ 个用空格分隔的正整数 $a_1, a_2, \dots, a_N$,表示给定的序列。

第三行包含 $K$ 个用空格分隔的正整数 $p_1, p_2, \dots, p_K$,每个整数定义了第 $i$ 场游戏($i = 1, 2, \dots, K$)的初始集合 $S$,该集合由给定序列的前 $p_i$ 个元素组成。

输出格式

程序应向标准输出打印 $K$ 行,每行包含一个整数,即对应游戏的结果。第 $i$ 行应包含第 $i$ 场游戏的结果(游戏按输入顺序从 $1$ 到 $K$ 编号)。

数据范围

  • $1 \le N \le 100\,000$
  • $1 \le K \le 2\,000$
  • $K \le N$
  • $1 \le a_i \le N$,对于 $i = 1, 2, \dots, N$
  • $1 \le p_i \le N$,对于 $i = 1, 2, \dots, K$
  • 在 $10\%$ 的测试用例中:$1 \le N \le 10$
  • 在 $30\%$ 的测试用例中:$1 \le N \le 600$
  • 在 $50\%$ 的测试用例中:$1 \le N \le 10\,000, 1 \le K \le 1\,000$

样例

样例输入 1

5 2
2 4 2 3 5
4 3

样例输出 1

2
6

说明

输入数据决定了程序将处理两场游戏。对于两场游戏,给定的序列相同,但第一场游戏的 $P = 4$,初始多重集 $S$ 为 $\{2, 4, 2, 3\}$;第二场游戏的 $P = 3$,初始多重集 $S$ 为 $\{2, 4, 2\}$。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.