struct LinearBasis {
ll base[35];
void init() {
memset(base, 0, sizeof base);
}
ll & operator [] (int pos) {
return base[pos];
}
bool insert(ll x) {
for(int i = 31; i >= 0; i--) {
if(x >> i & 1) {
if(!base[i]) {
base[i] = x;
return true;
}
x ^= base[i];
}
}
return false;
}
LinearBasis inter (const LinearBasis & t) {
LinearBasis ans, c = t, d = t;
ans.init();
for(int i = 0; i < 32; i++) {
if(!base[i]) continue;
int p = i;
ll x = base[i], temp = 0;
for(int j = i; j >= 0; j--) {
if(x >> j & 1) {
if(c[j]) {
x ^= c[j]; temp ^= d[j];
}
else {
p = j; break;
}
}
}
if(!x) {
ans[i] = temp;
}
else {
c[p] = x; d[p] = temp;
}
}
return ans;
}
};
线性基求交模板
最新推荐文章于 2022-12-06 17:04:46 发布