1
0
Fork 0

Add number/basis.cc

Signed-off-by: subcrip <contact@subc.rip>
This commit is contained in:
subcrip 2024-09-10 11:08:38 +08:00
parent f666edf536
commit 72fa16acd0
1 changed files with 22 additions and 0 deletions

22
number/basis.cc Normal file
View File

@ -0,0 +1,22 @@
// in-place modification
int basis(vector<ll>& a) {
int n = a.size();
int has = 0;
for (int i = 63; ~i and has < n; --i) {
for (int j = has; j < n; ++j) {
if (a[j] & (ll(1) << i)) {
swap(a[j], a[has]);
break;
}
}
if (not (a[has] & (ll(1) << i))) continue;
for (int j = 0; j < n; ++j) {
if (j == has) continue;
if (a[j] & (ll(1) << i)) {
a[j] ^= a[has];
}
}
++has;
}
return has;
}