From 72fa16acd0e67ebf33a15a9485e6d42cbdd65691 Mon Sep 17 00:00:00 2001 From: subcrip Date: Tue, 10 Sep 2024 11:08:38 +0800 Subject: [PATCH] Add number/basis.cc Signed-off-by: subcrip --- number/basis.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 number/basis.cc diff --git a/number/basis.cc b/number/basis.cc new file mode 100644 index 0000000..7443be2 --- /dev/null +++ b/number/basis.cc @@ -0,0 +1,22 @@ +// in-place modification +int basis(vector& 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; +}