CHEFTOWN - Editorial

I am using an (n+w)logn algorithm still it is showing time limit exceeded. please help. Thanks in advance
Link to Solution https://www.codechef.com/viewsolution/15525971