程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> CSU1656: Paper of FlyBrother(後綴數組)

CSU1656: Paper of FlyBrother(後綴數組)

編輯:C++入門知識

CSU1656: Paper of FlyBrother(後綴數組)


Description

FlyBrother is a superman, therefore he is always busy saving the world.
To graduate from NUDT is boring but necessary for him. Typically We need to post an paper to get Graduate Certificate, however being one superman, FlyBrother wants to make his paper perfect. A paper is a lower case string. To make it perfect, FlyBrother wanna the number of different substrings in the paper. It is quite a silly problem for FlyBrother, but because he is so busy, can you help him to solve it?

 

Input

There are several cases. Process till EOF.
For each case, there is a line of lower case string (1<=length<=100000).

 

Output

For each case, output one number in a line of the answer described in the problem.

 

Sample Input

a
aab

Sample Output

1
5

HINT


題意: 求不同的字符串個數
思路: 在我的後綴數組題目小結裡有一樣的的題目,模板題
#include 
#include 
#include 
#include 
#include 
#include
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

#define LS 2*i
#define RS 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define N 100005
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EXP 1e-8www.Bkjia.com
LL wa[N],wb[N],wsf[N],wv[N],sa[N];
LL rank1[N],height[N],s[N],a[N];
char str[N],str1[N],str2[N];
//sa:字典序中排第i位的起始位置在str中第sa[i]
//rank:就是str第i個位置的後綴是在字典序排第幾
//height:字典序排i和i-1的後綴的最長公共前綴
LL cmp(LL *r,LL a,LL b,LL k)
{
    return r[a]==r[b]&&r[a+k]==r[b+k];
}
void getsa(LL *r,LL *sa,LL n,LL m)//n要包含末尾添加的0
{
    LL i,j,p,*x=wa,*y=wb,*t;
    for(i=0; i=0; i--)  sa[--wsf[x[i]]]=i;
    p=1;
    j=1;
    for(; p=j)  y[p++]=sa[i]-j;
        for(i=0; i=0; i--)  sa[--wsf[wv[i]]]=y[i];
        t=x;
        x=y;
        y=t;
        x[sa[0]]=0;
        for(p=1,i=1; i


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved