A15318 | Xor-Subsequence (easy version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
It is the easy version of the problem. The only difference is that in this version $a_i \le 200$ .
You are given an array of $n$ integers $a_0, a_1, a_2, \ldots a_{n - 1}$ . Bryap wants to find the longest beautiful subsequence in the array.
An array $b = [b_0, b_1, \ldots, b_{m-1}]$ , where $0 \le b_0 < b_1 < \ldots < b_{m - 1} < n$ , is a subsequence of length $m$ of the array $a$ .
Subsequence $b = [b_0, b_1, \ldots, b_{m-1}]$ of length $m$ is called beautiful, if the following condition holds:
- For any $p$ ( $0 \le p < m - 1$ ) holds: $a_{b_p} \oplus b_{p+1} < a_{b_{p+1}} \oplus b_p$ .
Here $a \oplus b$ denotes the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of $a$ and $b$ . For example, $2 \oplus 4 = 6$ and $3 \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.
You are given an array of $n$ integers $a_0, a_1, a_2, \ldots a_{n - 1}$ . Bryap wants to find the longest beautiful subsequence in the array.
An array $b = [b_0, b_1, \ldots, b_{m-1}]$ , where $0 \le b_0 < b_1 < \ldots < b_{m - 1} < n$ , is a subsequence of length $m$ of the array $a$ .
Subsequence $b = [b_0, b_1, \ldots, b_{m-1}]$ of length $m$ is called beautiful, if the following condition holds:
- For any $p$ ( $0 \le p < m - 1$ ) holds: $a_{b_p} \oplus b_{p+1} < a_{b_{p+1}} \oplus b_p$ .
Here $a \oplus b$ denotes the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of $a$ and $b$ . For example, $2 \oplus 4 = 6$ and $3 \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.
输入格式
The first line contains a single integer $t$ ( $1 \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 $n$ ( $2 \leq n \leq 3 \cdot 10^5$ ) — the length of the array.
The second line of each test case contains $n$ integers $a_0,a_1,...,a_{n-1}$ ( $0 \leq a_i \leq 200$ ) — the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$ .
The first line of each test case contains a single integer $n$ ( $2 \leq n \leq 3 \cdot 10^5$ ) — the length of the array.
The second line of each test case contains $n$ integers $a_0,a_1,...,a_{n-1}$ ( $0 \leq a_i \leq 200$ ) — the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \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 \oplus 1 < 2 \oplus 0$ .
In the second test case, we can pick elements with indexes $1$ , $2$ and $4$ (in $0$ -indexation). For this elements holds: $2 \oplus 2 < 4 \oplus 1$ and $4 \oplus 4 < 1 \oplus 2$ .
In the second test case, we can pick elements with indexes $1$ , $2$ and $4$ (in $0$ -indexation). For this elements holds: $2 \oplus 2 < 4 \oplus 1$ and $4 \oplus 4 < 1 \oplus 2$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted