diff --git a/Linear-Basis.cpp b/Linear-Basis.cpp new file mode 100644 index 0000000..40dabd1 --- /dev/null +++ b/Linear-Basis.cpp @@ -0,0 +1,34 @@ +#include + +using namespace std; + +int n, d[100000], b[32], bsize; + +void linear_basis() +{ + for (int i = 0; i < n; i++) + { + for (int j = 30; j >= 0 && d[i] != 0; j--) + { + if ((d[i] >> j) == 0) continue; + else if (b[j] != 0) d[i] ^= b[j]; + else + { + b[j] = d[i]; + bsize++; + break; + } + } + } +} + +int main() +{ + scanf("%d", &n); + for (int i = 0; i < n; i++) + { + scanf("%d", &d[i]); + } + linear_basis(); + return 0; +}