B - Hamming Distance is not 1 Editorial by evima
Alternative SolutionThis is an alternative construction when \(q=1\) and \(L\) is odd and \(R\) is even.
Assume we have already determined that the number of elements in a set satisfying the conditions is \(\frac{R-L+1}{2}\) or \(\frac{R-L+3}{2}\).
Prepare \(R-L+1\) vertices corresponding to \(L,L+1,\dots,R\), and connect edges between two vertices that differ in exactly one digit in binary representation.
This graph is a bipartite graph with \(O((R-L)\log(R-L))\) edges, and what we seek is its maximum independent set.
The method for finding the maximum independent set from the maximum matching in a bipartite graph is well known, so we show how to construct the maximum matching.
If we flow matching so that \((L+1,L+2),(L+3,L+4), \dots (R-2,R-1)\) are matched, the additional flow we can send is at most \(1\).
By performing DFS or similar on the residual graph, we can find the maximum matching in \(O((R-L)\log(R-L))\).
posted:
last update: