Why Does my Q*(Log(n))^2 solution gives TLE in CLONEME ?

I did CLONEME by a q*(logn)^2 logic but that gave me tle in 3rd subtask, i tried to optimize the solution a lot but it didnt pass.

Link to solution : https://www.codechef.com/viewsolution/14203109

Logic : I did it using persistent segment trees. I stored count of elements as well as hash value of them in the tree. Then using binary search and qry function(which returns cumulative hash uptil required position) i found 1st xth position for a,b c,d such that cumulative hash uptil that xth position doesnt match. and checked the cumulative hash of the values on the right side of this position. If they are equal then print yes else no.

Even after loads of submissions with various optimisations, i coudnt remove the tle by this logic but i really want to know reason for tle considering my friends q*(logn)^3 logic passed. If anyone could tell me.

Later on i combined bs with qry and did in q*logn which passed.

See that’s just sad.

@luvk1412 did you got your solution to the problem because i am also facing the same problem!