diff --git a/number/basis-ng.cc b/number/basis-ng.cc new file mode 100644 index 0000000..ee83ea7 --- /dev/null +++ b/number/basis-ng.cc @@ -0,0 +1,34 @@ +template +struct basis { + array p; + int cnt = 0; + + basis(const vector& v) { + for (auto&& x : v) { + insert(x); + } + } + + bool insert(T x) { + for (size_t i = sizeof(T) * 8 - 1; ~i; --i) { + if (not (x >> i)) continue; + if (not p[i]) { + p[i] = x; + cnt += 1; + return true; + } + x ^= p[i]; + } + return false; + } + + vector value(void) const { + vector res; + for (size_t i = sizeof(T) * 8 - 1; ~i; --i) { + if (not p[i]) continue; + res.emplace_back(p[i]); + } + return res; + } +}; + diff --git a/trees/quick_union.cc b/trees/quick_union.cc index aea85b3..7aa4252 100644 --- a/trees/quick_union.cc +++ b/trees/quick_union.cc @@ -6,12 +6,12 @@ public: iota(c.begin(), c.end(), 0); sz.assign(n, 1); } - + size_t query(size_t i) { if (c[i] != i) c[i] = query(c[i]); return c[i]; } - + void merge(size_t i, size_t j) { if (connected(i, j)) return; sz[query(j)] += sz[query(i)];