ANUSAR TLE

I am getting TLE for this problem: http://www.codechef.com/problems/ANUSAR/

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: http://www.codechef.com/viewsolution/4149982

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: http://www.codechef.com/viewsolution/4164235

//