poj 1743 -- Musical Theme (后缀数组模板题)

就当存个模板

# include 
# include 
# include 
# include 
# include 
# include 
# include 
# include 
# include 
# include 
# include 
# include 
# include 

using namespace std ;

# define PB             push_back
# define SIZE(x)        (int)x.size()
# define clr(x,y)       memset(x,y,sizeof(x))
# define MP(x,y)        make_pair(x,y)
# define read(n)        scanf ( "%d" , & (n) )
# define reads(n)       scanf ( "%s" , n ) ;
# define ALL(t)         (t).begin(),(t).end()
# define FOR(i,n,m)     for ( int i = n ; i <= m ; i ++ )
# define code(x)        (x-'a')
# define IT             iterator

typedef long long               ll;
typedef unsigned int            uint;
typedef unsigned long long      ull;
typedef vector             vint;
typedef vector          vstring;

const ll mod = 1e9+7 ;
const ll LINF = 1e18 ;
const int INF = 1e9 ;
const double EPS = 1e-8;

const int maxn = 200005;
/*
字符要先转化为正整数
待排序的字符串放在r 数组中,从r[0]到r[n-1],长度为n,且最大值小于m。
所有的r[i]都大于0,r[n]无意义算法中置0
函数结束后,结果放在sa 数组中(名次从1..n),从sa[1]到sa[n]。s[0]无意义
*/
int sa[maxn],r[maxn];
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 makesa (int n,int m)//
{
        r[n++]=0;
        int i,j,p,*x=wa,*y=wb,*t;
        for(i=0; i=0; i--)sa[--ws1[x[i]]]=i;
        for(j=1,p=1; p=j) y[p++]=sa[i]-j;
                for(i=0; 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= len) return true;
                }
        }
        return false;
}

int main(){
        while (cin >> n,n) {
                FOR (i,0,n-1) read (r[i]);
                for (int i = n - 1 ; i ; i --) {
                        r[i] = r[i] - r[i - 1] + 90;
                }
                makesa (n,200);
                calheight (n);
                int low = 0 , high = n ;
                while (low <= high) {
                        int mid = (low + high) / 2;
                        if (check (mid))        low = mid + 1;
                        else    high = mid - 1;
                }
                if (low < 5)    cout << 0 << endl;
                else    cout << low << endl;
        }
}


你可能感兴趣的:(poj 1743 -- Musical Theme (后缀数组模板题))