2025“钉耙编程”中国大学生算法设计暑期联赛(2)——子集 · znzryb
## 思路讲解
这个子集确实还可以,不是很难,就是卡一下这个折半搜索01树。
你用线性基做基本不会被卡。
## AC代码
::: 源代码
```cpp
// by Gospel_rock
// from template_cpp
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define pb push_back
#define EB emplace_back
#define EM emplace
#define FI first
#define SE second
#define pct __builtin_popcountll
#define ctz __builtin_ctzll
#define SZ(a) ((long long) a.size())
#define FOR(i, a, b) for (long long i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (long long i = (a); i >= (b); --i)
#define debug(var) cerr << #var <<":"<<var<<"\n";
#define cend cerr<<"\n-----------\n"
#define lson(var) (var<<1)
#define rson(var) ((var<<1)+1)
#define fsp(x) fixed<<setprecision(x)
using namespace std;
using ll = long long;using ull = unsigned long long;
using DB=double;using LD=long double;
// using i128 = __int128;
using pdd = pair<DB,DB>;using plb = pair<ll,bool>;
using pll = pair<ll,ll>;using vll=vector<ll>;using vb=vector<bool>;
using vdb = vector<DB>;using vc=vector<char>;
using tll = tuple<ll,ll,ll>;
using vpll = vector<pll>;using vtll = vector<tll>;
using arr3 = array<ll,3> ;using arr2 = array<ll,2>;
constexpr ll MAXN=(ll)1e6+10,INF=(ll)1e17+9; // 1e18+9也是素数
constexpr ll mod=(ll)1e9+7; // 998244353;
constexpr double eps=1e-8;const double pi=acos(-1.0);
ll N,M,Q,X,K,T,lT;
inline void __();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>lT;
while(lT--)
__();
return 0;
}
/*
*/
// https://www.luogu.com.cn/record/228289095 基础模版
// 检测合并功能 https://acm.hdu.edu.cn/contest/view-code?cid=1173&rid=23716
struct LB{
using ll=long long;
ll n;vector<ll> b;
LB(ll n=62){
this->n=n;
b.assign(n+5,0);
}
void insert(ll x){
for(int i=n;i>=0;--i){
if(x>>i&1){
if(b[i]){
x^=b[i];
}else{
b[i]=x;
return;
}
}
}
}
ll findmx(){
ll res=0;
for(int i=n;i>=0;--i){
if((res^b[i]) > res){
res^=b[i];
}
}
return res;
}
void merge(const LB & t){
for(int i=n;i>=0;--i){
if(t.b[i]){
insert(t.b[i]);
}
}
}
};
inline void __(){
cin>>N;
vll A(N);
FOR(i,1,N){
cin>>A[i-1];
}
ll ans=0;
function <void(ll,LB)> dfs=[&](ll idx,LB lb)->void{
if(idx >= N) {
ans=max(ans,lb.findmx());
return;
}
LB llb=lb;lb.insert(A[idx]);llb.insert(A[idx]);
dfs(idx+2,lb);
dfs(idx+3,llb);
};
LB lb;
dfs(0,lb);
cout<<ans<<"\n";
}
/*
AC
https://acm.hdu.edu.cn/contest/view-code?cid=1173&rid=23716
*/
```
:::
## 心路历程(WA,TLE,MLE……)