https://codeforces.com/contest/1315/problem/D

can please someone help me how can we solve this problem in O(nlogn) time complexity