CF1717C.Madoka and Formal Statement

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Given an array of integer a1,a2,…,ana_1, a_2, \ldots, a_n. In one operation you can make ai:=ai+1a_i := a_i + 1 if i<ni \lt n and ai≤ai+1a_i \leq a_{i + 1}, or i=ni = n and ai≤a1a_i \leq a_1.

You need to check whether the array a1,a2,…,ana_1, a_2, \ldots, a_n can become equal to the array b1,b2,…,bnb_1, b_2, \ldots, b_n in some number of operations (possibly, zero). Two arrays aa and bb of length nn are called equal if ai=bia_i = b_i for all integers ii from 11 to nn.

给定一个整数数组 a1,a2,…,ana_1, a_2, \ldots, a_n。在一次操作中,你可以执行 ai:=ai+1a_i := a_i + 1,当且仅当以下条件之一成立:

  • i<ni < n 且 ai≤ai+1a_i \leq a_{i + 1};
  • 或 i=ni = n 且 ai≤a1a_i \leq a_1。

你需要判断:是否存在若干次(可能为零次)操作,使得数组 a1,a2,…,ana_1, a_2, \ldots, a_n 变为数组 b1,b2,…,bnb_1, b_2, \ldots, b_n。
长度为 nn 的两个数组 aa 和 bb 被称为相等,当且仅当对所有从 11 到 nn 的整数 ii,均有 ai=bia_i = b_i。

输入格式

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

The first line of each test case contains a single integer nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5) – the length of the array.

The second line of each test case contains nn integers a1,…,ana_1, \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,…,bnb_1, \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 \cdot 10^5.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤4⋅1041 \le t \le 4 \cdot 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5),表示数组的长度。

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

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

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

输出格式

For each test case, output "YES" if you can get the array bb, otherwise output "NO".

You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).

对于每个测试用例,如果可以得到数组 bb,则输出 “YES”,否则输出 “NO”。

您可以以任意大小写形式输出每个字母(例如,“YES”、“Yes”、“yes”、“yEs” 均会被识别为肯定回答)。

输入输出样例

  • 输入#1

    5
    3
    1 2 5
    1 2 5
    2
    2 2
    1 3
    4
    3 4 1 2
    6 4 2 5
    3
    2 4 1
    4 5 3
    5
    1 2 3 4 5
    6 5 6 7 6

    输出#1

    YES
    NO
    NO
    NO
    YES

说明/提示

In the first test case, the array aa is already equal to the array bb.

In the second test case, we can't get the array bb, because to do this we need to decrease a1a_1.

In the fifth test case, we can apply operations in order to the elements with indices 4,3,3,2,2,2,1,1,1,14, 3, 3,2,2,2,1,1,1,1, and then get the array [5,5,5,5,5][5,5,5,5,5]. After that, you can apply operations in order to elements with indices 5,4,4,3,15,4,4,3,1 and already get an array [6,5,6,7,6][6,5,6,7,6].

在第一个测试用例中,数组 aa 已经等于数组 bb。

在第二个测试用例中,我们无法得到数组 bb,因为要实现这一点,我们需要减小 a1a_1。

在第五个测试用例中,我们可以按顺序对下标为 4,3,3,2,2,2,1,1,1,14, 3, 3, 2, 2, 2, 1, 1, 1, 1 的元素执行操作,从而得到数组 [5,5,5,5,5][5,5,5,5,5]。之后,再按顺序对下标为 5,4,4,3,15, 4, 4, 3, 1 的元素执行操作,即可得到数组 [6,5,6,7,6][6,5,6,7,6]。

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

首页