Codeforces Round 815 (Div. 2)
D2
Xor-Subsequence (hard version)
Codeforces
2400
原题
← D1E →
翻译中…

It is the hard version of the problem. The only difference is that in this version $a_i \le 10^9$.

翻译中…

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 \lt b_1 \lt \ldots \lt b_{m - 1} \lt 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 \lt m - 1$) holds: $a_{b_p} \oplus b_{p+1} \lt a_{b_{p+1}} \oplus b_p$.
翻译中…

Here $a \oplus b$ denotes the bitwise 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.

翻译中…

Input

翻译中…

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 10^9$) — the elements of the array.

翻译中…

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

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

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

翻译中…

样例

Input #1
3
2
1 2
5
5 2 4 3 1
10
3 8 8 2 9 1 6 2 8 3
Output #1
2
3
6
InputCopy OutputCopy
题目信息
题号
1720D2
时间限制
2 s
内存限制
512 MB
标签
位运算
数据结构
动态规划
字符串
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。