CF2241D.An Alternative Way

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given two arrays aa and bb, each of length nn. You are allowed to perform the following operation on array aa any number of times (including zero):

  1. Choose two indices ll and rr such that 1≤l≤r≤n1 \le l \le r \le n;
  2. For each index ii from ll to rr (both inclusive),
    • Set ai:=ai−1a_i := a_i - 1 if i−li - l is odd.
    • Set ai:=ai+1a_i := a_i + 1 if i−li - l is even.

Determine whether you can make the array aa equal to the array bb by performing the operation any number of times.

给你两个长度均为 nn 的数组 aa 和 bb。你可以对数组 aa 执行以下操作任意多次(包括零次):

  1. 选择两个下标 ll 和 rr,满足 1≤l≤r≤n1 \le l \le r \le n;
  2. 对每个下标 ii(从 ll 到 rr,含端点):
    • 若 i−li - l 为奇数,则令 ai:=ai−1a_i := a_i - 1;
    • 若 i−li - l 为偶数,则令 ai:=ai+1a_i := a_i + 1。

判断是否可以通过若干次该操作使数组 aa 变为数组 bb。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. Description of each test case follows.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2\cdot10^5) — the length of the arrays aa and bb.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9) — the elements of the array aa.

The third line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (1≤bi≤1091 \le b_i \le 10^9) — the elements of the array bb.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052\cdot10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。接下来是每个测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2\cdot10^5)—— 数组 aa 和 bb 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9)—— 数组 aa 的元素。

每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(1≤bi≤1091 \le b_i \le 10^9)—— 数组 bb 的元素。

保证所有测试用例的 nn 之和不超过 2⋅1052\cdot10^5。

输出格式

For each test case, print "YES" if you can make array aa equal to array bb and "NO" otherwise.

You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).

对于每个测试用例,如果可以使数组 aa 等于数组 bb,则输出 "YES";否则输出 "NO"。

你可以以任意大小写形式输出 "YES" 和 "NO"(例如,字符串 "yEs"、"yes" 和 "Yes" 均被视为肯定回答)。

输入输出样例

  • 输入#1

    7
    3
    1 2 3
    1 2 3
    4
    1 4 5 2
    1 5 4 3
    1
    9
    8
    6
    6 7 6 7 6 7
    7 6 7 6 7 6
    9
    9 8 7 6 5 4 3 2 1
    9 9 8 2 4 4 3 5 3
    3
    1 1 2
    2 1 1
    2
    1 2
    1 1

    输出#1

    YES
    YES
    NO
    YES
    NO
    YES
    NO

说明/提示

For the first test case, arrays aa and bb are already equal.

For the second test case, let us choose l=2l = 2 and r=4r = 4. Now, we update the array aa in the following manner:

  • For i=2i = 2, we have i−l=2−2=0i - l = 2 - 2 = 0, which is even. Hence, set a2:=a2+1=4+1=5a_2 := a_2 + 1 = 4 + 1 = 5.
  • For i=3i = 3, we have i−l=3−2=1i - l = 3 - 2 = 1, which is odd. Hence, set a3:=a3−1=5−1=4a_3 := a_3 - 1 = 5 - 1 = 4.
  • For i=4i = 4, we have i−l=4−2=2i - l = 4 - 2 = 2, which is even. Hence, set a4:=a4+1=2+1=3a_4 := a_4 + 1 = 2 + 1 = 3.

Finally, we have array a=[1,5,4,3]a = [1, 5, 4, 3] and array b=[1,5,4,3]b = [1, 5, 4, 3].

For the third test case, it can be shown that it is impossible to make array aa equal to array bb.

对于第一个测试用例,数组 aa 和 bb 已经相等。

对于第二个测试用例,我们选择 l=2l = 2 和 r=4r = 4。现在,我们按如下方式更新数组 aa:

  • 对于 i=2i = 2,有 i−l=2−2=0i - l = 2 - 2 = 0,为偶数。因此,令 a2:=a2+1=4+1=5a_2 := a_2 + 1 = 4 + 1 = 5。
  • 对于 i=3i = 3,有 i−l=3−2=1i - l = 3 - 2 = 1,为奇数。因此,令 a3:=a3−1=5−1=4a_3 := a_3 - 1 = 5 - 1 = 4。
  • 对于 i=4i = 4,有 i−l=4−2=2i - l = 4 - 2 = 2,为偶数。因此,令 a4:=a4+1=2+1=3a_4 := a_4 + 1 = 2 + 1 = 3。

最终,得到数组 a=[1,5,4,3]a = [1, 5, 4, 3] 和数组 b=[1,5,4,3]b = [1, 5, 4, 3]。

对于第三个测试用例,可以证明无法使数组 aa 等于数组 bb。

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

首页