SUBST1 - New Distinct Substrings


Given a string, we need to find the total number of its distinct substrings.

Input

T- number of test cases. T<=20; Each test case consists of one string, whose length is <= 50000

Output

For each test case output one number saying the number of distinct substrings.

Example

Input:
2
CCCCC
ABABA

Output:
5
9

hide comments
(Tjandra Satria Gunawan)(曾毅昆): 2015-01-02 22:42:54

Here is my summary:
O(n*log^2(n)) --> definitely TLE even pointer opti used.
O(n*log(n)) --> longer code, AC
O(n) --> there're exist algorithm with this amortized complexity but very painful to code. I'm sure I this O(n) can get AC in 0.00s

Gaurav Babbar: 2014-10-23 21:11:03

SAM is givig TLE! what is the size of the input alphabet set??
----
AC after optimisatons :)

Last edit: 2014-10-24 21:15:36
Varun Gambhir: 2014-10-23 18:59:07

n*logn*logn algorithm for building suffix array gives tle :(

Ashish Kumar: 2014-05-13 14:48:00

Used suffix array with qsort function but it is giving tle??

Last edit: 2014-05-13 14:48:16
yhylord: 2014-04-26 06:07:37

Can SAM solve this problem? If S contains all characters in ASCII,then SAM will get MLE(TLE)...
--------
Now I've got TLE. How many cases does it has?

Last edit: 2014-04-29 14:35:19
innovolt: 2014-03-12 04:21:36

simple 1 .........sufffixxxxx array

aar: 2013-08-28 12:53:17

Suffix Array with O(n * logn *logn) is accepted...

jimmy: 2013-07-17 07:26:55

O(N*Log(N)^2) gets TLE..
@Jitendra i tried using qsort too. it gives TLE

aqfaridi: 2014-03-07 11:01:43

pointer arithmetic to speed up..

Abdullah Enes ÖNCÜ: 2013-04-18 04:35:07

why I get a RTE?


Added by:Hoang Hong Quan
Date:2006-01-18
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL6 VB.NET
Resource:Base on a problem in ByteCode06