Codeforces Round 1117 (Div. 2)
B
巨人之战
Gigantomachy
Codeforces
800
原题
← AC →

巨人之战AI (CI翻译)

Two giants, Bea and Ver, are playing a game. Each giant has his own mountain range. You have already measured all these mountains and now know that the heights of the mountains in Bea's range are $a_1, a_2, \ldots a_n$, and in Ver's range are $b_1, b_2, \ldots b_m$, with the mountains numbered from left to right for Bea and from right to left for Ver. At the beginning of the game, the giants stand on the mountain numbered $1$. Thus, they face each other and see all their mountains and all the mountains of their opponent. It turns out that Bea and Ver are connoisseurs of beauty, so the mountains in their ranges are arranged in non-increasing order, specifically $a_i \ge a_{i+1}$ for $1 \le i \lt n$ and $b_i \ge b_{i+1}$ for $1 \le i \lt m$.

两位巨人 Bea 和 Ver 正在进行一场游戏。每位巨人都有自己的山脉。你已经测量了所有山峰,现在知道 Bea 的山脉高度为 $a_1, a_2, \ldots a_n$,Ver 的山脉高度为 $b_1, b_2, \ldots b_m$。对于 Bea,山峰从左到右编号;对于 Ver,山峰从右到左编号。在游戏开始时,两位巨人都站在编号为 $1$ 的山峰上。因此,他们面对面站立,可以看到自己的所有山峰以及对手的所有山峰。事实证明,Bea 和 Ver 都是美学鉴赏家,因此他们山脉中的山峰按非递增顺序排列,具体来说,对于 $1 \le i \lt n$,有 $a_i \ge a_{i+1}$;对于 $1 \le i \lt m$,有 $b_i \ge b_{i+1}$。AI (CI翻译)

In the illustration below, there is an example of the initial arrangement, where Bea has the range $a_1, a_2, a_3 = 3, 2, 1$, and Ver has the range $b_1, b_2 = 4, 2$. For simplicity, the mountains are depicted as rectangles, with Bea's mountains on the left and Ver's on the right. For your good mood, the giants Bea and Ver are represented as beavers.

下图展示了初始状态的一个例子:Bea 的山脉为 $a_1, a_2, a_3 = 3, 2, 1$,Ver 的山脉为 $b_1, b_2 = 4, 2$。为简单起见,图中的山峰被画成了矩形,Bea 的山峰在左侧,Ver 的山峰在右侧。为了让你心情愉快,图中的 Bea 和 Ver 被表示成了海狸。AI (CI翻译)

image

imageAI (CI翻译)

Bea and Ver are not very smart, so on each turn they perform the same action. Specifically, the giant on his turn takes a boulder and throws it at the mountain on which his opponent is standing; as a result, the height of that mountain decreases by 1. If the giant on his turn sees that the mountain directly in front of him is higher (with a number one greater) than the one he is standing on, he jumps to it. If, however, the giant discovers that he is standing on regular ground (the height of the current mountain is 0) and there are no more mountains in front of him, he admits defeat. Bea goes first.

Bea 和 Ver 并不聪明,因此每回合都会执行相同的操作。具体来说,轮到某位巨人时,他会拿起一块巨石,将其扔向对手当前站立的山峰;于是,该山峰的高度减少 $1$。如果轮到某位巨人时,他发现正前方的山峰比自己当前站立的山峰高(恰好高 $1$),就会跳到那座山峰上。但是,如果某位巨人发现自己正站在普通地面上(当前山峰高度为 $0$),并且前方已经没有更多山峰,那么他就认输。Bea 先手。AI (CI翻译)

You know that their game can last a very long time, due to the enormous heights of the mountains and their quantities, so you want to determine who will win.

你知道,由于山峰高度和数量都非常大,这场游戏可能持续很长时间,因此请你判断谁会获胜。AI (CI翻译)

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of the test cases follows.

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

The first line of each test case contains two integers $n$ and $m$ — the number of mountains in the first and second giant's range, respectively ($1 \le n, m \le 100$).

每个测试用例的第一行包含两个整数 $n$ 和 $m$,分别表示第一位和第二位巨人山脉中的山峰数量($1 \le n, m \le 100$)。AI (CI翻译)

The second line of the test case contains $n$ integers $a_1, a_2, \ldots a_n$ — the heights of the mountains of the first giant ($1 \le a_i \le 10^9$; $a_i \ge a_{i+1}$).

每个测试用例的第二行包含 $n$ 个整数 $a_1, a_2, \ldots a_n$,表示第一位巨人的山峰高度($1 \le a_i \le 10^9$;$a_i \ge a_{i+1}$)。AI (CI翻译)

The third line of the test case contains $m$ integers $b_1, b_2, \ldots b_m$ — the heights of the mountains of the second giant ($1 \le b_i \le 10^9$; $b_i \ge b_{i+1}$).

每个测试用例的第三行包含 $m$ 个整数 $b_1, b_2, \ldots b_m$,表示第二位巨人的山峰高度($1 \le b_i \le 10^9$;$b_i \ge b_{i+1}$)。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, output a single number — the number of the giant who will win.

对于每个测试用例,输出一个整数,表示获胜巨人的编号。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first test case, on his very first turn, Bea will reduce the height of Ver's only mountain to $0$ and win.

在第一个测试用例中,Bea 在她的第一个回合就会将 Ver 唯一一座山峰的高度降为 $0$,并获胜。AI (CI翻译)

In the second test case, Bea will reduce the height of Ver's mountain to $1$, and Ver will win on his next turn.

在第二个测试用例中,Bea 会将 Ver 的山峰高度降为 $1$,而 Ver 会在下一回合获胜。AI (CI翻译)

In the third test case, during the first $3$ rounds, the heights of Bea's and Ver's mountains will decrease to $1$. Then Bea will reduce the height of Ver's mountain to $0$, but Ver still has one mountain left, and on his turn, he jumps onto it and wins by reducing the height of Bea's only mountain to $0$.

在第三个测试用例中,在前 $3$ 轮中,Bea 和 Ver 的山峰高度都会降为 $1$。随后 Bea 会将 Ver 的山峰高度降为 $0$,但 Ver 仍然还有一座山峰;在自己的回合中,Ver 跳到那座山峰上,并将 Bea 唯一一座山峰的高度降为 $0$,从而获胜。AI (CI翻译)

样例

Input #1
6
1 1
1
1
1 1
1
2
1 2
4
4 1
4 2
4 3 2 1
10 1
4 2
4 3 2 1
6 5
4 2
4 3 2 1
7 5
Output #1
1
2
2
2
1
2
InputCopy OutputCopy
题目信息
题号
2257B
时间限制
1 s
内存限制
256 MB
标签
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。