AND Square Subsegments, need help

I have implemented same idea as described in editorial, but it’s getting TLE. Here is my solution. It’s same as this one
Please help why it’s getting TLE.

Bumping at his issue.

//