I have implemented an 2N^2logN solution for this problem which obviously giving TLE. I just want to know will an O(NlogN) solution is enough for this problem or do I need fast IO too?

Hey this is not a good question to ask. If you can solve that problem, then you can try to submit it using fast I/O too.

If that does n’t work, then try to optimize your solution.