Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 大家一起用（罗穗骞）的模版

Posted by useit at 2009-08-03 14:01:26 on Problem 2774
```#include <iostream>
using namespace std;
const int  maxn =100005*2;
/*

*/
int cmp(int *r,int a,int b,int l)//
{
return r[a]==r[b]&&r[a+l]==r[b+l];
}
int wa[maxn],wb[maxn],wv[maxn],ws1[maxn];
void da(int *r,int *sa,int n,int m)//
{
r[n++]=0;
int i,j,p,*x=wa,*y=wb,*t;
for(i=0;i<m;i++)ws1[i]=0;
for(i=0;i<n;i++)ws1[x[i]=r[i]]++;
for(i=1;i<m;i++)ws1[i]+=ws1[i-1];
for(i=n-1;i>=0;i--)sa[--ws1[x[i]]]=i;
for(j=1,p=1;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++) ws1[i]=0;
for(i=0;i<n;i++) ws1[wv[i]]++;
for(i=1;i<m;i++) ws1[i]+=ws1[i-1];
for(i=n-1;i>=0;i--) sa[--ws1[wv[i]]]=y[i];
for(t=x,x=y,y=t,p=1,x[sa[0]]=0,i=1;i<n;i++)
x[sa[i]]=cmp(y,sa[i-1],sa[i],j)?p-1:p++;
}
}
/*
height[2..n]:height[i]保存的是lcp(sa[i],sa[i-1])
rank[0..n-1]:rank[i]保存的是原串中suffix[i]的名次
*/
int rank[maxn],height[maxn];
void calheight(int *r,int *sa,int n)
{
int i,j,k=0;
for(i=1;i<=n;i++)rank[sa[i]]=i;
for(i=0;i<n;height[rank[i++]]=k)
for(k?k--:0,j=sa[rank[i]-1];r[i+k]==r[j+k];k++);
}
int lcp(int i,int j)//原串中suffix[i]与suffix[j]的lcp
{	//rmq解决
//rank[i]<rank[j]
//return min(height[ rank[i]+1 ]......height[ rank[j] ])
return 0;
}```

Followed by: