Setter: Tahsin Masrur
Tester and alternate writer: Rafid Bin Mostofa
Techniques: Euler Tour or DFS Time, Persistent Trie
First find the starting time and ending time of all the nodes of tree using a DFS. Consider the array of time, the subarray starting at starting time of node (denoted by from now on) and ending time of () represents the subtree rooteed at . So basically, you need to find the -th number among all the numbers in the subarrays and after XOR-ing them with . If we had to do this for a single array always, it'd be easy with Trie, a well-known problem. For our problem, we need to maintain persistent trie i.e. keeping a version of trie for each time in the array of DFS time. We can then just consider the four versions relevant to each query and walk down the tries accordingly to find the solution.
Time complexity: O()
Space complexity: O()