XOR Profit Solution

Is there a way to solve this problem in less than O(n^2) time complexity?


Refer to this link please