Language: C++


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
#include<bitset>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson i<<1,l,mid
#define rson i<<1|1,mid+1,r
#define llson j<<1,l,mid
#define rrson j<<1|1,mid+1,r
#define INF 0x7fffffff
#define maxn 110010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void radix(int *str,int *a,int *b,int n,int m)
{
    static int count[maxn];
    mem(count,0);
    for(int i=0; i<n; i++) ++count[str[a[i]]];
    for(int i=1; i<=m; i++) count[i]+=count[i-1];
    for(int i=n-1; i>=0; i--) b[--count[str[a[i]]]]=a[i];
}
void suffix(int *str,int *sa,int n,int m) //倍增算法计算出后缀数组sa
{
    static int rank[maxn],a[maxn],b[maxn];
    for(int i=0; i<n; i++) rank[i]=i;
    radix(str,rank,sa,n,m);
    rank[sa[0]]=0;
    for(int i=1; i<n; i++)
        rank[sa[i]]=rank[sa[i-1]]+(str[sa[i]]!=str[sa[i-1]]);
    for(int i=0; 1<<i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            a[j]=rank[j]+1;
            b[j]=j+(1<<i)>=n?0:rank[j+(1<<i)]+1;
            sa[j]=j;
        }
        radix(b,sa,rank,n,n);
        radix(a,rank,sa,n,n);
        rank[sa[0]]=0;
        for(int j=1; j<n; j++)
            rank[sa[j]]=rank[sa[j-1]]+(a[sa[j-1]]!=a[sa[j]]||b[sa[j-1]]!=b[sa[j]]);
    }
}
void calcHeight(int *str,int *sa,int *h,int *rank,int n) //求出最长公共前缀数组h
{
    int k=0;
    h[0]=0;
    for(int i=0; i<n; i++) rank[sa[i]]=i;
    for(int i=0; i<n; i++)
    {
        k=k==0?0:k-1;
        if(rank[i])
            while(str[i+k]==str[sa[rank[i]-1]+k]) k++;
        else k=0;
        h[rank[i]]=k;
    }
}
int a[maxn],sa[maxn],height[maxn],rank[maxn];
int v[maxn],Max[15],Min[15],r,n,len,j;
char s[10002];
bool judge(int m)
{
    mem(Max,0);mem(Min,100);
    for(int i=1; i<len; i++)
    {
        if(height[i]<m)
        {
            mem(Max,0);mem(Min,100);
            Max[v[sa[i]]]=sa[i];
            Min[v[sa[i]]]=sa[i];
        }
        else
        {
            Max[v[sa[i]]]=max(Max[v[sa[i]]],sa[i]);
            Min[v[sa[i]]]=min(Min[v[sa[i]]],sa[i]);
            Max[v[sa[i-1]]]=max(Max[v[sa[i-1]]],sa[i-1]);
            Min[v[sa[i-1]]]=min(Min[v[sa[i-1]]],sa[i-1]);
            for(j=1;j<=n;j++)
                if(Max[j]-Min[j]<m) break;
            if(j>n) return true;
        }
    }
    return false;
}
int binary()
{
    int ans=0,mid,l=0;
    while(l<=r)
    {
        mid=(l+r)>>1;
        if(judge(mid)) ans=mid,l=mid+1;
        else r=mid-1;
    }
    return ans;
}
int main()
{
    //freopen("1.txt","r",stdin);
    
        // scanf("%d",&n);
        len=r=j=0;
        n = 1;
        for(int i=1; i<=n; i++)
        {
            int len1;
            scanf("%d", &len1);
            scanf("%s",s);
            if(r<len1>>1) r=len1>>1;//二分上限
            for(int k=0; k<len1; k++)
                a[len+k]=s[k]+5,v[len+k]=i;//v记录在哪个串中
            a[len+len1]=++j;//字符串中间用没出现过的字符隔开
            v[len+len1]=0;
            len=len+len1+1;
        }
        len--;
        suffix(a,sa,len,256);
        calcHeight(a,sa,height,rank,len);
        printf("%d\n",binary());
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:125:32: error: reference to 'rank' is ambiguous
  125 |         calcHeight(a,sa,height,rank,len);
      |                                ^~~~
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:66:35: note:                 'int rank [110010]'
   66 | int a[maxn],sa[maxn],height[maxn],rank[maxn];
      |                                   ^~~~