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 <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
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-8
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<m; i++) wsf[i]=0;
for(i=0; i<n; i++) wsf[x[i]=r[i]]++;
for(i=1; i<m; i++) wsf[i]+=wsf[i-1];
for(i=n-1; i>=0; i--) sa[--wsf[x[i]]]=i;
p=1;
j=1;
for(; p<n; j*=2,m=p)
{
for(p=0,i=n-j; i<n; i++) y[p++]=i;
for(i=0; i<n; i++) if(sa[i]>=j) y[p++]=sa[i]-j;
for(i=0; i<n; i++) wv[i]=x[y[i]];
for(i=0; i<m; i++) wsf[i]=0;
for(i=0; i<n; i++) wsf[wv[i]]++;
for(i=1; i<m; i++) wsf[i]+=wsf[i-1];
for(i=n-1; 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<n; i++)
x[sa[i]]=cmp(y,sa[i-1],sa[i],j)? p-1:p++;
}
}
void getheight(LL *r,LL n)//n不保存最后的0
{
LL i,j,k=0;
for(i=1; i<=n; i++) rank1[sa[i]]=i;
for(i=0; i<n; i++)
{
if(k)
k--;
else
k=0;
j=sa[rank1[i]-1];
while(r[i+k]==r[j+k])
k++;
height[rank1[i]]=k;
}
}
LL t,ans,n,m; int main()
{
LL i,j,k,len;
W(~scanf("%s",str))
{
len = strlen(str);
UP(i,0,len-1)
s[i]=str[i];
s[len] = 0;
getsa(s,sa,len+1,300);
getheight(s,len);
ans = (1+len)*len/2;
UP(i,2,len)
ans-=height[i];
printf("%lld\n",ans);
}
}

最新文章

  1. 好玩的Handler
  2. csv大文件分割以及添加表头
  3. 一个表格说明RelativeLayout中的几个重要属性【Written By KillerLegend】
  4. 数据导出为excel表格
  5. 继承TextView简单画一个尺子
  6. 项目中的那些事---JavaScript
  7. EXTJS 4.2 资料 控件之Grid 行编辑绑定下拉框,并点一次触发一次事件
  8. Linux以百万兆字节显示内存大小
  9. 协议系列之TCP协议
  10. php的运行机制
  11. 等价路由在路由器和CE交换机上默认的行为是不同的,路由器总是走第一个下一跳,CE交换机是逐包。
  12. 来自师兄的Django2.0笔记摘录
  13. Nodejs 和 Electron ubuntu下快速安装
  14. (转)Java大数操作(BigInteger、BigDecimal)
  15. 转载:VS项目属性配置总结
  16. 2018.09.14 codechef Milestone(随机化算法)
  17. 本机的虚拟机执行ifconfig,显示不出ip的解决方法
  18. mono+jexus 部署之CompilationException
  19. 如何运用 Powershell 修改Office365和AD账户
  20. Delphi XE 4,Rad Studio XE 4 官方下载,更新Update 1(附破解)

热门文章

  1. 使程序在Linux下后台运行 (关掉终端继续让程序运行的方法)
  2. 基于Linux平台的Lotus Domino 8系统部署五部曲(全视频展示)
  3. Codefroces Educational Round 26 837 D. Round Subset
  4. eclipse工作空间配置导出
  5. 03007_JDBC概述
  6. 牛客网剑指offer刷题总结
  7. Qt样式表之盒子模型(以QSS来讲解,而不是CSS)
  8. node --进行后台的环境搭建
  9. JavaFx lineChart real-time Monitor
  10. HDU 多校联合 6045