CF1375C.Element Extermination

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array aa of length nn, which initially is a permutation of numbers from 11 to nn. In one operation, you can choose an index ii (1≤i<n1 \leq i \lt n) such that ai<ai+1a_i \lt a_{i + 1}, and remove either aia_i or ai+1a_{i + 1} from the array (after the removal, the remaining parts are concatenated).

For example, if you have the array [1,3,2][1, 3, 2], you can choose i=1i = 1 (since a1=1<a2=3a_1 = 1 \lt a_2 = 3), then either remove a1a_1 which gives the new array [3,2][3, 2], or remove a2a_2 which gives the new array [1,2][1, 2].

Is it possible to make the length of this array equal to 11 with these operations?

给你一个长度为 nn 的数组 aa,该数组初始时是 11 到 nn 的一个排列。在一次操作中,你可以选择一个下标 ii(满足 1≤i<n1 \leq i \lt n),使得 ai<ai+1a_i \lt a_{i + 1},然后从数组中删除 aia_i 或 ai+1a_{i + 1} 中的任意一个(删除后,剩余部分会直接拼接)。

例如,若当前数组为 [1,3,2][1, 3, 2],你可以选择 i=1i = 1(因为 a1=1<a2=3a_1 = 1 \lt a_2 = 3),然后删除 a1a_1,得到新数组 [3,2][3, 2];或者删除 a2a_2,得到新数组 [1,2][1, 2]。

能否通过若干次上述操作,使该数组的长度变为 11?

输入格式

The first line contains a single integer tt (1≤t≤2⋅1041 \leq t \leq 2 \cdot 10^4) — the number of test cases. The description of the test cases follows.

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

The second line of each test case contains nn integers a1a_1, a2a_2, ..., ana_n (1≤ai≤n1 \leq a_i \leq n, aia_i are pairwise distinct) — elements of the array.

It is guaranteed that the sum of nn over all test cases doesn't exceed 3⋅1053 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤2⋅1041 \leq t \leq 2 \cdot 10^4)——测试用例的数量。随后是各测试用例的描述。

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

每个测试用例的第二行包含 nn 个整数 a1a_1, a2a_2, ..., ana_n(1≤ai≤n1 \leq a_i \leq n,且 aia_i 两两互不相同)——数组的元素。

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

输出格式

For each test case, output on a single line the word "YES" if it is possible to reduce the array to a single element using the aforementioned operation, or "NO" if it is impossible to do so.

对于每个测试用例,如果可以通过上述操作将数组缩减为单个元素,则在一行中输出单词 “YES”;否则(即无法做到),输出 “NO”。

输入输出样例

  • 输入#1

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

    输出#1

    YES
    YES
    NO
    YES

说明/提示

For the first two test cases and the fourth test case, we can operate as follow (the bolded elements are the pair chosen for that operation):

[1,2,3]→[1,2]→[1][\text{1}, \textbf{2}, \textbf{3}] \rightarrow [\textbf{1}, \textbf{2}] \rightarrow [\text{1}]

[3,1,2,4]→[3,1,4]→[3,4]→[4][\text{3}, \textbf{1}, \textbf{2}, \text{4}] \rightarrow [\text{3}, \textbf{1}, \textbf{4}] \rightarrow [\textbf{3}, \textbf{4}] \rightarrow [\text{4}]

[2,4,6,1,3,5]→[4,6,1,3,5]→[4,1,3,5]→[4,1,5]→[4,5]→[4][\textbf{2}, \textbf{4}, \text{6}, \text{1}, \text{3}, \text{5}] \rightarrow [\textbf{4}, \textbf{6}, \text{1}, \text{3}, \text{5}] \rightarrow [\text{4}, \text{1}, \textbf{3}, \textbf{5}] \rightarrow [\text{4}, \textbf{1}, \textbf{5}] \rightarrow [\textbf{4}, \textbf{5}] \rightarrow [\text{4}]

对于前两个测试用例和第四个测试用例,我们可以按如下方式操作(加粗的元素表示该次操作所选的数对):

[1,2,3]→[1,2]→[1][\text{1}, \textbf{2}, \textbf{3}] \rightarrow [\textbf{1}, \textbf{2}] \rightarrow [\text{1}]

[3,1,2,4]→[3,1,4]→[3,4]→[4][\text{3}, \textbf{1}, \textbf{2}, \text{4}] \rightarrow [\text{3}, \textbf{1}, \textbf{4}] \rightarrow [\textbf{3}, \textbf{4}] \rightarrow [\text{4}]

[2,4,6,1,3,5]→[4,6,1,3,5]→[4,1,3,5]→[4,1,5]→[4,5]→[4][\textbf{2}, \textbf{4}, \text{6}, \text{1}, \text{3}, \text{5}] \rightarrow [\textbf{4}, \textbf{6}, \text{1}, \text{3}, \text{5}] \rightarrow [\text{4}, \text{1}, \textbf{3}, \textbf{5}] \rightarrow [\text{4}, \textbf{1}, \textbf{5}] \rightarrow [\textbf{4}, \textbf{5}] \rightarrow [\text{4}]

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

首页