CF1720D1.Xor-Subsequence (easy version)

传统题 时间 2000 ms 内存 512 MiB 10 尝试 1 已通过 1 标签

Xor-Subsequence (easy version)

CF1720D1 · Xor-Subsequence (easy version)

  • 难度:1800
  • 标签:bitmasks、brute force、dp、strings、trees、two pointers
  • 链接:https://codeforces.com/problemset/problem/1720/D1
  • 时间限制:2 seconds 内存限制:512 megabytes
  • 出现位置:Day22-阶段模拟4-S T1-T3综合卷

英文原题面

Statement

It is the easy version of the problem. The only difference is that in this version ai200a_i \le 200. You are given an array of nn integers a0,a1,a2,an1a_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,,bm1]b = [b_0, b_1, \ldots, b_{m-1}], where $0 \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,,bm1]b = [b_0, b_1, \ldots, b_{m-1}] of length mm is called beautiful, if the following condition holds:

  • For any pp (0p<m10 \le p \lt m - 1) holds: $a_{b_p} \oplus b_{p+1} \lt a_{b_{p+1}} \oplus b_p$.

Here aba \oplus b denotes the bitwise XOR of aa and bb. For example, 24=62 \oplus 4 = 6 and 31=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.

Input

The first line contains a single integer tt (1t1051 \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 (2n31052 \leq n \leq 3 \cdot 10^5) — the length of the array. The second line of each test case contains nn integers a0,a1,...,an1a_0,a_1,...,a_{n-1} (0ai2000 \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 31053 \cdot 10^5.

Output

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

输出:

2
3
6

样例解释(英文原文)

In the first test case, we can pick the whole array as a beautiful subsequence because 11<201 \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: 22<412 \oplus 2 \lt 4 \oplus 1 and 44<124 \oplus 4 \lt 1 \oplus 2.

在线编程 IDE

建议全屏模式获得最佳体验