new distingct substring (spoj)

problem link : link

I have already solved distinct substring (spoj : link text) but new distinct substring have strict timelimit.Please give me hint…thanks