OCTOBER LUNCHTIME DDQUERY Subtask 2 HELP

Can someone tell me how to approach the DDQUERY problem from October lunchtime?
I have solved the subtask 1 but the judge is showing TLE for subtask 2’s last 3 test cases

1 Like