题意:求数组的最长子序列,子序列满足相邻两项 abp⊕bp+1<abp+1⊕bp
分析:二进制字典树dp。(抄jls的,简单分析了一下)
#include<bits/stdc++.h>
// cout<<fixed<<setprecision(8);
//#pragma GCC optimize(2)
#define ms(x,n) memset(x,n,sizeof x)
#define endl '\n'
#define pii pair<int,int>
#define M(a,b) make_pair(a,b)
#define fi first
#define se second
#define pb push_back
#define __builtin_popcount popcnt1//getcnt
#define db1(x) cerr<<#x<<"="<<(x)<<" "
#define db2(x) cerr<<#x<<"="<<(x)<<"\n"
//#define int long long
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll _gcd(ll a, ll b) { return b > 0 ? _gcd(b, a % b) : a; }
int popcnt1(ll x) { int ans = 0;for (int j = 0;j <= 60;j++)if (x & (1ll << j)) ans++;return ans; }
template <typename T> inline void read(T& t) { int f = 0, c = getchar(); t = 0;while (!isdigit(c)) f |= c == '-', c = getchar();while (isdigit(c)) t = t * 10 + c - 48, c = getchar();if (f) t = -t; }
template <typename T> void print(T x) { if (x < 0) x = -x, putchar('-');if (x > 9) print(x / 10);putchar(x % 10 + 48); }
const double pi = acos(-1.0);
const double eps = 1e-7;//有时候精度可能不够
const int inf = 0x3f3f3f3f;
const ll Inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
ll power(ll n, ll x) { ll res = 1;ll q = n % mod;while (x) { if (x & 1) res = (res * q) % mod;q = q * q % mod;x /= 2; }return res; }
const int N = 3e5*31+10;
int n, m, t, k;
int a[N];
int trie[N][2], f[N][2];
int dp[N / 31];
int cnt = 0;
int newnode() {
cnt++;
trie[cnt][0] = trie[cnt][1] = 0;
f[cnt][0] = f[cnt][1] = 0;
return cnt;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
cnt = 0;
for (int i = 0;i < n;i++) {
dp[i] = 0;
}
newnode();
for (int i = 0;i < n;i++) {
cin >> a[i];
int x = a[i] ^ i;
int p = 1;
for (int j = 30;j >= 0;j--) {
//db2(p);
int v = x >> j & 1;
dp[i] = max(dp[i], f[trie[p][v ^ 1]][i >> j & 1]);
p = trie[p][v];
if (!p) break;
}
dp[i]++;
p = 1;
for (int j = 30;j >= 0;j--) {
int v = x >> j & 1;
if (!trie[p][v]) {
trie[p][v] = newnode();
}
p = trie[p][v];
f[p][a[i] >> j & 1] = max(f[p][a[i] >> j & 1], dp[i]);
}
}
int ans = 0;
for (int i = 0;i < n;i++) {
//db1(i), db2(dp[i]);
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
return 0;
}