ANUSAR TLE

I am getting TLE for this problem: ANUSAR Problem - CodeChef

Don’t know why, with my understanding my solution is O(nlogn). But still TLE.

I have used the suffix array implementation in other problems, and its ok I guess.

My solution: CodeChef: Practical coding for everyone

Can anyone help me. Thanks in advance.

In line 74, “memset(c, 0, sizeof c); // clear frequency table”

This needs MAX_N * (Q ≤ 200000) operations in the worst case.

I tested corrected code and it runs in time: CodeChef: Practical coding for everyone