1
0
Fork 0
cp-templates/number/basis-ng.cc

35 lines
712 B
C++
Raw Normal View History

2025-01-18 12:24:23 +00:00
template <typename T>
struct basis {
array<T, sizeof(T) * 8> p;
int cnt = 0;
basis(const vector<T>& 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<T> value(void) const {
vector<T> res;
for (size_t i = sizeof(T) * 8 - 1; ~i; --i) {
if (not p[i]) continue;
res.emplace_back(p[i]);
}
return res;
}
};