Technique
XOR Linear Basis (Gaussian elimination over GF(2))
Reduce numbers to at most B independent vectors over GF(2) to answer max subset XOR, count distinct subset XORs, or membership.
Learn firstBit Tricks & Bitmasking
0%
mastery
0/5 solved
0/5 solved
Recognise it
The signal
maximum XOR of any SUBSET
1Brute force
Enumerate all subsets.
2The observation
2n subsets: the span of a basis of size <= B describes all of them.
3Why it works
Basis vectors have distinct leading bits and span exactly the subset XORs seen so far.
Reach for it when
- +number of distinct subset XOR values (2^rank)
- +k-th smallest subset XOR
Not when
- ×pairwise (not subset) XOR (binary-trie)
Practice
0/5 solved
- Maximum Xor SubsetCSESHard
- Number of Subset XorsCSESHard
- K Subset XorsCSESHard
- Square SubsetsCSESHard
- Mahmoud and Ehab and yet another xor taskCodeforces2400
Pitfalls
Misconceptions
- !confusing subset XOR with subarray XOR (prefix-xor + trie)