I have implemented as per the algorithm suggested in the EDU section (here), however it gets MLE for some reason. The memory complexity should be O(m log m) which shouldn't be too much.
Can anyone tell me how to optimize this code (for Step 3 Problem C — Dynamic Connectivity Offline) for memory. I believe my code is logically correct, however it get MLE on (hidden) testcase 2. I have tried all the optimizations I could think of.
Also I think that the pseudocode in the EDU section (here) is not correct. In the base case, we should apply the unions applicable over that leaf, since the query segment could have been split in such a way that it covers only the leaf. Please correct me if I am wrong.