CF1720D1.Xor-Subsequence (easy version)

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

It is the easy version of the problem. The only difference is that in this version ai≤200a_i \le 200.

You are given an array of nn integers a0,a1,a2,…an−1a_0, a_1, a_2, \ldots a_{n - 1}. Bryap wants to find the longest beautiful subsequence in the array.

An array b=[b0,b1,…,bm−1]b = [b_0, b_1, \ldots, b_{m-1}], where 0≤b0<b1<…<bm−1<n0 \le b_0 \lt b_1 \lt \ldots \lt b_{m - 1} \lt n, is a subsequence of length mm of the array aa.

Subsequence b=[b0,b1,…,bm−1]b = [b_0, b_1, \ldots, b_{m-1}] of length mm is called beautiful, if the following condition holds:

  • For any pp (0≤p<m−10 \le p \lt m - 1) holds: abp⊕bp+1<abp+1⊕bpa_{b_p} \oplus b_{p+1} \lt a_{b_{p+1}} \oplus b_p.

Here a⊕ba \oplus b denotes the bitwise XOR of aa and bb. For example, 2⊕4=62 \oplus 4 = 6 and 3⊕1=23 \oplus 1=2.

Bryap is a simple person so he only wants to know the length of the longest such subsequence. Help Bryap and find the answer to his question.

这是该问题的简单版本。唯一的区别是,在此版本中 ai≤200a_i \le 200。

给定一个包含 nn 个整数的数组 a0,a1,a2,…,an−1a_0, a_1, a_2, \ldots, a_{n - 1}。Bryap 想要在该数组中找出最长的“优美子序列”。

若 b=[b0,b1,…,bm−1]b = [b_0, b_1, \ldots, b_{m-1}] 满足 0≤b0<b1<…<bm−1<n0 \le b_0 \lt b_1 \lt \ldots \lt b_{m - 1} \lt n,则称其为数组 aa 的一个长度为 mm 的子序列。

长度为 mm 的子序列 b=[b0,b1,…,bm−1]b = [b_0, b_1, \ldots, b_{m-1}] 被称为“优美”的,当且仅当满足以下条件:

  • 对任意 pp(其中 0≤p<m−10 \le p \lt m - 1),均有:abp⊕bp+1<abp+1⊕bpa_{b_p} \oplus b_{p+1} \lt a_{b_{p+1}} \oplus b_p。

此处 a⊕ba \oplus b 表示 aa 与 bb 的按位异或运算。例如,2⊕4=62 \oplus 4 = 6,且 3⊕1=23 \oplus 1 = 2。

Bryap 是一位简单的人,因此他只想知道最长此类子序列的长度。请帮助 Bryap,求出该问题的答案。

输入格式

The first line contains a single integer tt (1≤t≤1051 \leq t \leq 10^5) — 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 a0,a1,...,an−1a_0,a_1,...,a_{n-1} (0≤ai≤2000 \leq a_i \leq 200) — the elements of the array.

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

第一行包含一个整数 tt(1≤t≤1051 \leq t \leq 10^5),表示测试用例的数量。随后是各测试用例的描述。

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

每个测试用例的第二行包含 nn 个整数 a0,a1,...,an−1a_0,a_1,...,a_{n-1}(0≤ai≤2000 \leq a_i \leq 200),表示数组的元素。

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

输出格式

For each test case print a single integer — the length of the longest beautiful subsequence.

对于每个测试用例,输出一个整数——最长优美子序列的长度。

输入输出样例

  • 输入#1

    3
    2
    1 2
    5
    5 2 4 3 1
    10
    3 8 8 2 9 1 6 2 8 3

    输出#1

    2
    3
    6

说明/提示

In the first test case, we can pick the whole array as a beautiful subsequence because 1⊕1<2⊕01 \oplus 1 \lt 2 \oplus 0.

In the second test case, we can pick elements with indexes 11, 22 and 44 (in 00-indexation). For this elements holds: 2⊕2<4⊕12 \oplus 2 \lt 4 \oplus 1 and 4⊕4<1⊕24 \oplus 4 \lt 1 \oplus 2.

在第一个测试用例中,我们可以选择整个数组作为优美的子序列,因为 1⊕1<2⊕01 \oplus 1 \lt 2 \oplus 0。

在第二个测试用例中,我们可以选择索引为 11、22 和 44 的元素(采用 00-索引)。对于这些元素,满足:2⊕2<4⊕12 \oplus 2 \lt 4 \oplus 1 且 4⊕4<1⊕24 \oplus 4 \lt 1 \oplus 2。

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

首页