CF2241D.An Alternative Way
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two arrays a and b, each of length n. You are allowed to perform the following operation on array a any number of times (including zero):
- Choose two indices l and r such that 1≤l≤r≤n;
- For each index i from l to r (both inclusive),
- Set ai:=ai−1 if i−l is odd.
- Set ai:=ai+1 if i−l is even.
Determine whether you can make the array a equal to the array b by performing the operation any number of times.
给你两个长度均为 n 的数组 a 和 b。你可以对数组 a 执行以下操作任意多次(包括零次):
- 选择两个下标 l 和 r,满足 1≤l≤r≤n;
- 对每个下标 i(从 l 到 r,含端点):
- 若 i−l 为奇数,则令 ai:=ai−1;
- 若 i−l 为偶数,则令 ai:=ai+1。
判断是否可以通过若干次该操作使数组 a 变为数组 b。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases. Description of each test case follows.
The first line of each test case contains a single integer n (1≤n≤2⋅105) — the length of the arrays a and b.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the elements of the array a.
The third line of each test case contains n integers b1,b2,…,bn (1≤bi≤109) — the elements of the array b.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。接下来是每个测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 数组 a 和 b 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 数组 a 的元素。
每个测试用例的第三行包含 n 个整数 b1,b2,…,bn(1≤bi≤109)—— 数组 b 的元素。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, print "YES" if you can make array a equal to array b 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).
对于每个测试用例,如果可以使数组 a 等于数组 b,则输出 "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 a and b are already equal.
For the second test case, let us choose l=2 and r=4. Now, we update the array a in the following manner:
- For i=2, we have i−l=2−2=0, which is even. Hence, set a2:=a2+1=4+1=5.
- For i=3, we have i−l=3−2=1, which is odd. Hence, set a3:=a3−1=5−1=4.
- For i=4, we have i−l=4−2=2, which is even. Hence, set a4:=a4+1=2+1=3.
Finally, we have array a=[1,5,4,3] and array b=[1,5,4,3].
For the third test case, it can be shown that it is impossible to make array a equal to array b.
对于第一个测试用例,数组 a 和 b 已经相等。
对于第二个测试用例,我们选择 l=2 和 r=4。现在,我们按如下方式更新数组 a:
- 对于 i=2,有 i−l=2−2=0,为偶数。因此,令 a2:=a2+1=4+1=5。
- 对于 i=3,有 i−l=3−2=1,为奇数。因此,令 a3:=a3−1=5−1=4。
- 对于 i=4,有 i−l=4−2=2,为偶数。因此,令 a4:=a4+1=2+1=3。
最终,得到数组 a=[1,5,4,3] 和数组 b=[1,5,4,3]。
对于第三个测试用例,可以证明无法使数组 a 等于数组 b。
输入解题思路,AI测评打分。不知道怎么写?