Lunchtime July 2021 - Beautiful Pairs

Why PBDS solution gives TLE ?
I have solved the problem using lower bound but I want to know why PBDS is giving TLE it works in O(log(n))…

Problem Link :- CodeChef: Practical coding for everyone
TLE solution :- CodeChef: Practical coding for everyone
Ac solution :- CodeChef: Practical coding for everyone