There is this problem https://www.codechef.com/problems/GERALD07. I tried solving it using Mo algorithm but I am stuck with the dsu. Like when I am going to move left pointer rightwards or right pointer leftwards, then I would need to break the set previously merged. I am not getting how to break the joined set. Plus I know it can be solved by link-cut, but I haven't read that topic so kindly give me suggestions with regard to Mo algorithm. Thanks!