CF2257B.Gigantomachy

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 a1,a2,…ana_1, a_2, \ldots a_n, and in Ver's range are b1,b2,…bmb_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 11. 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 ai≥ai+1a_i \ge a_{i+1} for 1≤i<n1 \le i \lt n and bi≥bi+1b_i \ge b_{i+1} for 1≤i<m1 \le i \lt m.

In the illustration below, there is an example of the initial arrangement, where Bea has the range a1,a2,a3=3,2,1a_1, a_2, a_3 = 3, 2, 1, and Ver has the range b1,b2=4,2b_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 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.

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.

两位巨人——比娅(Bea)和维尔(Ver)——正在玩一个游戏。每位巨人各自拥有一座山脉。你已经测量了所有这些山峰,现已得知:比娅的山脉高度依次为 a1,a2,…,ana_1, a_2, \ldots, a_n,维尔的山脉高度依次为 b1,b2,…,bmb_1, b_2, \ldots, b_m;其中,比娅的山峰从左到右编号,而维尔的山峰则从右到左编号。游戏开始时,两位巨人均站在编号为 11 的山峰上。因此,他们彼此相向而立,能看见自己全部的山峰以及对方全部的山峰。事实上,比娅和维尔都是美学鉴赏家,因此他们各自山脉中的山峰高度呈非递增排列,即满足 ai≥ai+1a_i \ge a_{i+1}(对所有 1≤i<n1 \le i < n),且 bi≥bi+1b_i \ge b_{i+1}(对所有 1≤i<m1 \le i < m)。

下图展示了一个初始布局示例:比娅的山脉为 a1,a2,a3=3,2,1a_1, a_2, a_3 = 3, 2, 1,维尔的山脉为 b1,b2=4,2b_1, b_2 = 4, 2。为简化起见,山峰以矩形表示,比娅的山峰位于左侧,维尔的山峰位于右侧。为让你心情愉悦,巨人比娅和维尔被描绘成两只河狸。

比娅和维尔并不太聪明,因此在每一轮中,他们都执行完全相同的操作。具体而言:轮到某位巨人行动时,他拾起一块巨石,朝对手当前所站的山峰投掷;结果,该山峰的高度减少 11。此外,若该巨人发现正前方(编号比当前所在山峰大 11 的)山峰更高,则他会跳至那座山峰上。然而,若该巨人发现自己正站在平地上(即当前山峰高度为 00),且前方已无任何山峰,则他认输。比娅先行。

你已知,由于山峰高度极大、数量众多,这场游戏可能持续极长时间;因此,你希望确定最终谁将获胜。

输入格式

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

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

The second line of the test case contains nn integers a1,a2,…ana_1, a_2, \ldots a_n — the heights of the mountains of the first giant (1≤ai≤1091 \le a_i \le 10^9; ai≥ai+1a_i \ge a_{i+1}).

The third line of the test case contains mm integers b1,b2,…bmb_1, b_2, \ldots b_m — the heights of the mountains of the second giant (1≤bi≤1091 \le b_i \le 10^9; bi≥bi+1b_i \ge b_{i+1}).

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤5001 \le t \le 500)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm —— 分别表示第一位巨人和第二位巨人领地中的山峰数量(1≤n,m≤1001 \le n, m \le 100)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…ana_1, a_2, \ldots a_n —— 表示第一位巨人的山峰高度(1≤ai≤1091 \le a_i \le 10^9;且满足 ai≥ai+1a_i \ge a_{i+1})。

每个测试用例的第三行包含 mm 个整数 b1,b2,…bmb_1, b_2, \ldots b_m —— 表示第二位巨人的山峰高度(1≤bi≤1091 \le b_i \le 10^9;且满足 bi≥bi+1b_i \ge b_{i+1})。

输出格式

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

对于每个测试用例,输出一个数字——获胜的巨人的编号。

输入输出样例

  • 输入#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

    输出#1

    1
    2
    2
    2
    1
    2

说明/提示

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

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

In the third test case, during the first 33 rounds, the heights of Bea's and Ver's mountains will decrease to 11. Then Bea will reduce the height of Ver's mountain to 00, 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 00.

在第一个测试用例中,贝娅在她的第一回合就会将维的唯一一座山的高度减少至 00 并获胜。

在第二个测试用例中,贝娅会将维的山的高度减少至 11,而维将在他的下一回合获胜。

在第三个测试用例中,在前 33 轮中,贝娅和维各自的山的高度都将减少至 11。接着贝娅将维的山的高度减少至 00,但维仍剩下一座山;轮到维行动时,他跳上那座山,并通过将贝娅唯一的山的高度减少至 00 而获胜。

输入解题思路,AI测评打分。不知道怎么写?

首页