At the beginning of WA, always thought it was the time to write their own forward extension of the wrong, and later found that the St was wrong to write
The priority of the +-*/is higher than the bitwise operation priority, and subsequent operations with unclear precedence must be bracketed
#include <stdio.h> #include <string.h> #include <algorithm> #include <math.h>using namespace STD; #define N 100010char s[n];int r[n],wa[n],wb[n],wv[n],ws[n],sa[n],rank[n],height[n];bool cmp (int *r,int a,int B,int L) {return r[a]==r[b]&&r[a+l]==r[b+l]; } void da (int *r,int *sa,int n,int m) {int i,j,p,*x=wa,*y=wb; for (i=0;i<m;i++) ws[i]=0; for (i=0;i<n;i++) ws[x[i]=r[i]]++; for (i=1;i<m;i++) ws[i]+=ws[i-1]; for (i=n-1;i>=0;i--) sa[--ws[x[i]]]=i; for (j=1,p=1;p<n;j<<=1,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++) ws[i]=0; for (i=0;i<n;i++) ws[wv[i]]++; for (i=1;i<m;i++) ws[i]+=ws[i-1]; for (i=n-1;i>=0;i--) sa[--ws[wv[i]]]=y[i]; Swap (x, y); for (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++;} return; } void calheight (int *r,int *sa,int n) {int i,j,k=0;for (i=1;i<=n;i++) rank[sa[i]]=i;//i is ranked 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++);//for (i=1;i<=n;i++) printf ("height[%d]:%d\n", I, Height[i]); return;} int dp[n][25];void init_rmq (int N) {int i,j;for (i=1;i<=n;i++) dp[i][0]=height[i];//rank because a 0 is added to the last surface, the value is in 1-nfor (j=1; 1<<J) <=n;j++) {//1<<j table length for (i=n;i;i--) {//positive order? Reverse? Dp[i][j]=dp[i][j-1];if (i+ (1<< (j-1)) <=n) dp[i][j]=min (dp[i][j],dp[i+ (1<< (j-1))][j-1]);// Note that the bitwise operation must be in parentheses, the +-*/is higher than the bitwise operation priority}}}int QUERY_RMQ (int l,int r) {//query the longest common prefix int a=rank[l],b=rank[r];if (a>b) swap (A, b);// Because here is rank, the ranking is not necessarily l in front of the a++;//according to the definition of the height array needs to add 1 int k=log (b-a+1.0)/log (2.0);//b-a+1: Length return min (dp[a][k],dp[b-(1 <<k) +1][k]);} int main () {#ifndef online_judgefreopen ("In.txt", "R", stdin), #endifint cas=1;while (scanf ("%s", s)) {if (s[0]== ' # ') Break;int N=strlen (s); int l=0;int i;for (i=0;i<n;i++) R[l++]=s[i];r[l]=0;da (r,sa,l+1,129); calheIght (r,sa,l); INIT_RMQ (L);p rintf ("Case%d:", cas++); int ans=1;//facilitates first assignment int post=0;int max_len=1,k,re,add,p;int len,j; for (len=1;len<=n/2;len++) {for (I=0;i+len<n;i+=len) {if (R[i]!=r[i+len]) continue;k=query_rmq (I,i+len); re=k/ len+1;//Number of repetitions p=i;add=i-(Len-k%len);//number of cycles +1 points for (j=i-1;j>=0&&j+len>i&&r[j]==r[j+len];j--) {//here can not be written j>=left, because the suffix may have superfluous, but does not constitute a cycle, so directly to the front extension len-1 characters can be//because here add r[j]==r[j+len], so long as the cycle can continue, then LCP has been sliding scale, When LCP can gather the integer multiples of Len, the number of cycles is +1 if (j==add) {re++;p =add;} else if (Rank[j]<rank[p]) {p=j;}} if (Re>ans) {Ans=re;post=p;max_len=len;} else if (Re==ans&&rank[p]<rank[post]) {Post=p;max_len=len;}}} if (ans==1) printf ("%c", R[sa[1]]), Else for (i=post;i<max_len*ans+post;i++) printf ("%c", R[i]);p rintf ("\ n");} return 0;}
POJ 3693 Maximum Repetition substring