//模板
const int maxbit = 63; //maxbit不能太大
struct L_B{
ll lba[maxbit], p[maxbit];
int cnt;
L_B(){
memset(lba, 0, sizeof(lba));
memset(p, 0, sizeof(p));
cnt = 0;
}
/*
bool Insert(ll val){ //插入
for(int i = maxbit - 1; i >= 0; -- i){
if(val & (1ll << i)){
if(!lba[i]){
lba[i] = val;
break;
}
val ^= lba[i];
}
}
return val > 0;
}
*/
void Insert(ll val){ //插入
for(int i = maxbit - 1; i >= 0; -- i)
if(val & (1ll << i)){
if(!lba[i]){
lba[i] = val;
break;
}
val ^= lba[i];
}
}
/* 不常用
ll Size(){
ll num = 0;
for(int i = maxbit; i >= 0; -- i){
if(lba[i]) num ++;
}
return num;
}
*/
ll query_max(){ //查找最大值
ll res = 0;
for(int i = maxbit - 1; i >= 0; -- i){
ll che = res ^ lba[i];
if(che > res) res^=lba[i];
}
return res;
}
ll query_min(){ //查找最小值
for(int i = 0; i <= maxbit; ++ i)
if(lba[i])
return lba[i];
return 0;
}
void rebuild(){ //重构
for(int i = maxbit - 1; i >= 0; -- i){
for(int j = i - 1; j >= 0; -- j)
if(lba[i] & (1ll << j)) lba[i] ^= lba[j];
}
for(int i = 0; i <= maxbit - 1; ++ i){
if(lba[i]) p[cnt ++] = lba[i];
}
}
ll query_kth(ll k){ //求第k个
int res = 0;
if(k >= (1ll << cnt)) return -1;
for(int i = maxbit - 1; i >= 0; -- i){
if(k & (1ll << i)) res ^= p[i];
}
return res;
}
bool check(ll x){ //判断x在不在这个线性基中
for(int i= maxbit - 1; i >= 0 ; -- i)
if(x & (1ll << i)) x ^= lba[i];
return x==0;
}
};
L_B Merge(const L_B &n1, const L_B &n2){ //合并
L_B res = n1;
for(int i = maxbit - 1; i >= 0; -- i)
if(n2.lba[i]) res.Insert(n1.lba[i]);
return res;
}