CF1604B.XOR Specia-LIS-t

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

YouKn0wWho has an integer sequence a1,a2,…ana_1, a_2, \ldots a_n. Now he will split the sequence aa into one or more consecutive subarrays so that each element of aa belongs to exactly one subarray. Let kk be the number of resulting subarrays, and h1,h2,…,hkh_1, h_2, \ldots, h_k be the lengths of the longest increasing subsequences of corresponding subarrays.

For example, if we split [2,5,3,1,4,3,2,2,5,1][2, 5, 3, 1, 4, 3, 2, 2, 5, 1] into [2,5,3,1,4][2, 5, 3, 1, 4], [3,2,2,5][3, 2, 2, 5], [1][1], then h=[3,2,1]h = [3, 2, 1].

YouKn0wWho wonders if it is possible to split the sequence aa in such a way that the bitwise XOR of h1,h2,…,hkh_1, h_2, \ldots, h_k is equal to 00. You have to tell whether it is possible.

The longest increasing subsequence (LIS) of a sequence b1,b2,…,bmb_1, b_2, \ldots, b_m is the longest sequence of valid indices i1,i2,…,iki_1, i_2, \ldots, i_k such that i1<i2<…<iki_1 \lt i_2 \lt \ldots \lt i_k and bi1<bi2<…<bikb_{i_1} \lt b_{i_2} \lt \ldots \lt b_{i_k}. For example, the LIS of [2,5,3,3,5][2, 5, 3, 3, 5] is [2,3,5][2, 3, 5], which has length 33.

An array cc is a subarray of an array bb if cc can be obtained from bb by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

YouKn0wWho 有一个整数序列 a1,a2,…,ana_1, a_2, \ldots, a_n。现在他要将序列 aa 划分为一个或多个连续的子数组,使得 aa 中的每个元素恰好属于其中一个子数组。设划分后得到 kk 个子数组,且 h1,h2,…,hkh_1, h_2, \ldots, h_k 分别为这些子数组的最长上升子序列(LIS)的长度。

例如,若将 [2,5,3,1,4,3,2,2,5,1][2, 5, 3, 1, 4, 3, 2, 2, 5, 1] 划分为 [2,5,3,1,4][2, 5, 3, 1, 4]、[3,2,2,5][3, 2, 2, 5]、[1][1],则对应的 h=[3,2,1]h = [3, 2, 1]。

YouKn0wWho 想知道:是否存在一种划分方式,使得 h1,h2,…,hkh_1, h_2, \ldots, h_k 的按位异或(bitwise XOR) 结果等于 00?你需要判断是否可行。

序列 b1,b2,…,bmb_1, b_2, \ldots, b_m 的最长上升子序列(LIS) 是指满足如下条件的最长索引序列 i1,i2,…,iki_1, i_2, \ldots, i_k:i1<i2<…<iki_1 \lt i_2 \lt \ldots \lt i_k,且 bi1<bi2<…<bikb_{i_1} \lt b_{i_2} \lt \ldots \lt b_{i_k}。例如,[2,5,3,3,5][2, 5, 3, 3, 5] 的 LIS 是 [2,3,5][2, 3, 5],其长度为 33。

若数组 cc 可通过从数组 bb 的开头删除若干(可能为零或全部)元素,并从结尾删除若干(可能为零或全部)元素而得到,则称 cc 是 bb 的一个子数组(subarray)。

输入格式

The first line contains a single integer tt (1≤t≤10 0001 \le t \le 10\,000) — the number of test cases.

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

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).

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

第一行包含一个整数 tt(1≤t≤10 0001 \le t \le 10\,000)—— 表示测试用例的数量。

每个测试用例的第一行包含一个整数 nn(2≤n≤1052 \le n \le 10^5)。

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

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

输出格式

For each test case, print "YES" (without quotes) if it is possible to split into subarrays in the desired way, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).

对于每个测试用例,如果可以按要求将数组划分为若干子数组,则输出 "YES"(不带引号);否则输出 "NO"(不带引号)。每个字母可使用任意大小写形式(大写或小写)。

输入输出样例

  • 输入#1

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

    输出#1

    YES
    NO
    YES
    YES

说明/提示

In the first test case, YouKn0wWho can split the sequence in the following way: [1,3,4][1, 3, 4], [2,2][2, 2], [1,5][1, 5]. This way, the LIS lengths are h=[3,1,2]h = [3, 1, 2], and the bitwise XOR of the LIS lengths is 3⊕1⊕2=03 \oplus 1 \oplus 2 = 0.

In the second test case, it can be shown that it is impossible to split the sequence into subarrays that will satisfy the condition.

在第一个测试用例中,YouKn0wWho 可以将序列如下分割:[1,3,4][1, 3, 4]、[2,2][2, 2]、[1,5][1, 5]。此时,各子数组的最长递增子序列(LIS)长度为 h=[3,1,2]h = [3, 1, 2],这些 LIS 长度的按位异或值为 3⊕1⊕2=03 \oplus 1 \oplus 2 = 0。

在第二个测试用例中,可以证明无法将该序列分割成满足条件的子数组。

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

首页