QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#14965. Nene的游戏

Statistics

Nene 发明了一种基于递增整数序列 $a_1, a_2, \ldots, a_k$ 的新游戏。

在这个游戏中,最初有 $n$ 名玩家排成一列。游戏的每一轮都会发生以下情况:

  • Nene 找出当前队列中第 $a_1$ 位、第 $a_2$ 位、$\ldots$、第 $a_k$ 位的玩家。这些玩家会被同时踢出游戏。如果某轮中需要踢出第 $i$ 位的玩家,但当前队列中的人数少于 $i$ 人,则该操作被跳过。

当某一轮中没有任何人被踢出游戏时,所有留在游戏中的玩家即为获胜者。

例如,考虑 $a=[3, 5]$ 且初始有 $n=5$ 名玩家的游戏。设玩家按初始顺序依次为 ABCDE。过程如下:

  • 第一轮开始前,玩家队列为 ABCDE。Nene 找出第 $3$ 位和第 $5$ 位的玩家,即 CE。他们在第一轮中被踢出。
  • 现在玩家队列为 ABD。Nene 找出第 $3$ 位和第 $5$ 位的玩家。第 $3$ 位是 D,但队列中没有第 $5$ 位玩家。因此,只有 D 在第二轮中被踢出。
  • 在第三轮中,没有人被踢出游戏,因此游戏在这一轮结束后终止。
  • 玩家 AB 被宣布为获胜者。

Nene 尚未决定最初会有多少人参加游戏。她给了你 $q$ 个整数 $n_1, n_2, \ldots, n_q$,你需要针对每个 $1 \le i \le q$ 独立地回答以下问题:

  • 如果游戏最初有 $n_i$ 名玩家,会有多少人获胜?

输入格式

每个测试点包含多个测试用例。第一行包含测试用例的数量 $t$ ($1 \le t \le 250$)。接下来是各测试用例的描述。

每个测试用例的第一行包含两个整数 $k$ 和 $q$ ($1 \le k, q \le 100$),分别表示序列 $a$ 的长度和需要求解的 $n_i$ 的数量。

第二行包含 $k$ 个整数 $a_1, a_2, \ldots, a_k$ ($1 \le a_1 < a_2 < \ldots < a_k \le 100$),即序列 $a$。

第三行包含 $q$ 个整数 $n_1, n_2, \ldots, n_q$ ($1 \le n_i \le 100$)。

输出格式

对于每个测试用例,输出 $q$ 个整数:第 $i$ ($1 \le i \le q$) 个整数表示当初始有 $n_i$ 名玩家参加游戏时,获胜者的数量。

样例

输入 1

6
2 1
3 5
5
5 3
2 4 6 7 9
1 3 5
5 4
3 4 5 6 7
1 2 3 4
2 3
69 96
1 10 100
1 1
100
50
3 3
10 20 30
1 10 100

输出 1

2 
1 1 1 
1 2 2 2 
1 10 68 
50 
1 9 9

说明

第一个测试用例已在题目描述中解释。

在第二个测试用例中,当 $n=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.