Comments

In this approach we will try to iterate over all subsets of mask in a smarter way. A noticeable flaw in our previous approach is that an index A[x] with x having K off bits is visited by 2^K masks. Thus there is repeated recalculation

Can someone explain me this line?

The mask: 4(100) has 2 off-bits, so 2^2=4 masks will visit the mask 4(100). How?

but your rating doesnt justify it

https://www.codechef.com/SEPT17/problems/FILLMTR can be solved using dsu as well as normal dfs

can you please explain the logic of this optimisation