CF2164A.Sequence Game

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Given an integer sequence of length nn denoted as a1,a2,…,ana_1,a_2,\ldots,a_n and an integer xx.

You can perform the following operation: select two adjacent numbers aia_i and ai+1a_{i+1} and replace them with an integer yy, which satisfies min⁡(ai,ai+1)≤y≤max⁡(ai,ai+1)\min(a_i,a_{i+1}) \le y \le \max(a_i,a_{i+1}). After the replacement, the original aia_i and ai+1a_{i+1} are removed from the sequence, and the elements are renumbered from 11 to n−1n-1.

For example, for a=[1,2,4,5]a=[1,2,4,5] you can select a2=2a_2=2 and a3=4a_3=4, and replace them with 33. After that, aa becomes [1,3,5][1,3,5]. However, you cannot select a1=1a_1=1 and a2=2a_2=2 and replace them with 33 (since yy is bigger than max⁡(ai,ai+1)\max(a_i,a_{i+1}), nor can you select a1=1a_1=1 and a3=4a_3=4 (the selected numbers should be adjacent).

Clearly, after performing n−1n-1 operations, only one number will remain. The question is whether this final number can be exactly equal to xx.

给定一个长度为 nn 的整数序列 a1,a2,…,ana_1,a_2,\ldots,a_n 和一个整数 xx。

你可以执行如下操作:选择两个相邻的数 aia_i 和 ai+1a_{i+1},并用一个整数 yy 替换它们,其中 yy 满足 min⁡(ai,ai+1)≤y≤max⁡(ai,ai+1)\min(a_i,a_{i+1}) \le y \le \max(a_i,a_{i+1})。替换后,原 aia_i 和 ai+1a_{i+1} 从序列中被移除,剩余元素重新编号为 11 到 n−1n-1。

例如,对 a=[1,2,4,5]a=[1,2,4,5],你可以选择 a2=2a_2=2 和 a3=4a_3=4,并用 33 替换它们;之后 aa 变为 [1,3,5][1,3,5]。但你不能选择 a1=1a_1=1 和 a2=2a_2=2 并用 33 替换它们(因为 yy 超过了 max⁡(ai,ai+1)\max(a_i,a_{i+1})),也不能选择 a1=1a_1=1 和 a3=4a_3=4(所选数字必须相邻)。

显然,经过 n−1n-1 次操作后,序列中将仅剩一个数。问题是:这个最终的数能否恰好等于 xx?

输入格式

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 one integer nn (1≤n≤1001 \le n \le 100).

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (−109≤ai≤109-10^9 \le a_i \le 10^9).

The third line of each test case contains one integer xx (−109≤x≤109-10^9 \le x \le 10^9).

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

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(−109≤ai≤109-10^9 \le a_i \le 10^9)。

每个测试用例的第三行包含一个整数 xx(−109≤x≤109-10^9 \le x \le 10^9)。

输出格式

For each test case, output "YES" (without quotes) if the final number can be exactly equal to xx, 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).

对于每个测试用例,如果最终的数字可以恰好等于 xx,则输出 "YES"(不带引号);否则输出 "NO"。

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

输入输出样例

  • 输入#1

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

    输出#1

    YES
    NO
    YES

说明/提示

In the first test case, you can first select a2=7a_2=7 and a3=5a_3=5, and replace them with 66. After that, aa becomes [2,6][2, 6]. Now you can select a1=2a_1=2 and a2=6a_2=6, and replace them with 44.

In the second test case, it can be shown that the final number can never be 88.

在第一个测试用例中,你可以首先选择 a2=7a_2=7 和 a3=5a_3=5,并将它们替换为 66。此后,数组 aa 变为 [2,6][2, 6]。现在你可以选择 a1=2a_1=2 和 a2=6a_2=6,并将它们替换为 44。

在第二个测试用例中,可以证明最终得到的数永远不可能是 88。

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

首页