I observed that we can pair up nodes from the root(1)′sroot(1)′s children and thier respective subtreessubtrees as long as we can, Then the left over nodes in each children's subtree can be paired iffiff they are leaves? I don't know a fast way to do all this? What's the...
For each query we go up to the root. So, we change v from a to 1 (excluding) with a = a / 2. Then for each v we take its parent p and p's other child u (if it exists). We could easily take p into account and then take all u's subtree using precalculated data...