Language: C++

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
char c[10004];
int sa[10004];
struct p{
	int a;
	int b;
}rank[10004];
p* rank2[10004];
vector<p*> v[10004];
int siz[10004];
int len;
int height[10004],h[10004];//h[a]=height[rank[a].a-1]
int f[10004][16];
int log2(int a){
	if(a==0)return -1;
	return log2(a/2)+1;
}
void STbiao(){
	for(int i=0;i<=log2(len);i++){
		for(int j=0;j<len+1-(1<<i);j++){
			if(i==0)f[j][i]=height[j];
			else{
				if(f[j][i-1]>f[j+(1<<(i-1))][i-1]){
					f[j][i]=f[j+(1<<(i-1))][i-1];
				}else{
					f[j][i]=f[j][i-1];
				}
			}
			//cout<<f[j][i]<<" ";
		}
		//cout<<endl;
	}
}
int RMQ(int aa,int bb){
	if(aa>bb){
		int temp=aa;aa=bb;bb=temp;
	}
	int cc=bb-aa;
	cc=log2(cc+1);
	if(f[aa][cc]>f[bb-(1<<cc)+1][cc]){
		return f[bb-(1<<cc)+1][cc];
	}else{
		return f[aa][cc];
	}
}
inline int mlcp(int a,int b){
	int g=0;
	while(c[a]==c[b]){
		a++;b++;g++;
	}
	return g;
}
inline int lcp(int a,int b){
	if(a==b)return len-a;
	a=rank[a].a-1;
	b=rank[b].a-1;
	if(a>b)a^=b,b^=a,a^=b;
	//cout<<a<<" "<<b<<endl;
	return RMQ(a+1,b);
}
inline int gzsa1(int a,int b){
	return c[a]<c[b];
}
void n(){
	cin>>len;
	cin>>c;
	c[len+1]=0;
	int g=1;
	for(int i=0;i<len;i++){
		sa[i]=i;
	}
	sort(sa,sa+len,gzsa1);
	int tmp=0;char cc=0;
	for(int i=0;i<len;i++){
		if(cc!=c[sa[i]]){
			cc=c[sa[i]];
			tmp++;
		}
		rank[sa[i]].a=tmp;
	}
	for(int i=0;i<len;i++){
		rank[i].b=0;
	}
	while(g<len){
		for(int i=0;i<len;i++){
			if(i+g<len)rank[i].b=rank[i+g].a;
			else rank[i].b=0;
			v[rank[i].b].push_back(rank+i);
			siz[rank[i].b]++;
		}
		int tmp1=0;
		for(int i=0;i<=len;i++){
			for(int j=0;j<siz[i];j++){
				rank2[tmp1]=v[i][j];
				tmp1++;
			}
			v[i].clear();
			siz[i]=0;
			if(tmp1==len)break;
		}
		for(int i=0;i<len;i++){
			v[rank2[i]->a].push_back(rank2[i]);
			siz[rank2[i]->a]++;
		}
		tmp1=0;
		for(int i=0;i<=len;i++){
			for(int j=0;j<siz[i];j++){
				rank2[tmp1]=v[i][j];
				tmp1++;
			}
			v[i].clear();
			siz[i]=0;
			if(tmp1==len)break;
		}
		int tmpa=0,tmpb=0,tmp=0;
		for(int i=0;i<len;i++){
			if(rank2[i]->a!=tmpa || rank2[i]->b!=tmpb){
				tmpa=rank2[i]->a;
				tmpb=rank2[i]->b;
				tmp++;
			}
			rank2[i]->a=tmp;
		}
		g*=2;
	}
	for(int i=0;i<len;i++){
		sa[rank[i].a-1]=i;
	}
	/*printf("\nrank: ");
	for(int i=0;i<len;i++){
		printf("%d ",rank[i].a);
	}
	printf("\nsa: ");
	for(int i=0;i<len;i++){
		printf("%d ",sa[i]);
	}*/
	for(int i=0;i<len;i++){
		if(rank[i].a==1)height[rank[i].a-1]=h[i]=0;
		else if(i==1 || h[i-1]<=1){
			height[rank[i].a-1]=h[i]=mlcp(sa[rank[i].a-2],sa[rank[i].a-1]);
		}else{
			height[rank[i].a-1]=h[i]=mlcp(sa[rank[i].a-2]+h[i-1]-2,sa[rank[i].a-1]+h[i-1]-2)+h[i-1]-2;
		}
	}
	/*printf("\nheight: ");
	for(int i=0;i<len;i++){
		printf("%d ",height[i]);
	}
	cout<<endl<<endl<<endl;*/
	int ans=0;
	for(int i=1;i<len;i++){
		ans=max(ans,min(abs(sa[i]-sa[i-1]),height[i]));
	}
	printf("%d\n",ans);
}
int main(){
	n();
}

Compiler output:
a.cc: In function 'int lcp(int, int)':
a.cc:60:11: error: reference to 'rank' is ambiguous
   60 |         a=rank[a].a-1;
      |           ^~~~
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:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:61:11: error: reference to 'rank' is ambiguous
   61 |         b=rank[b].a-1;
      |           ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc: In function 'void n()':
a.cc:84:17: error: reference to 'rank' is ambiguous
   84 |                 rank[sa[i]].a=tmp;
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:87:17: error: reference to 'rank' is ambiguous
   87 |                 rank[i].b=0;
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:91:36: error: reference to 'rank' is ambiguous
   91 |                         if(i+g<len)rank[i].b=rank[i+g].a;
      |                                    ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:91:46: error: reference to 'rank' is ambiguous
   91 |                         if(i+g<len)rank[i].b=rank[i+g].a;
      |                                              ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:92:30: error: reference to 'rank' is ambiguous
   92 |                         else rank[i].b=0;
      |                              ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:93:27: error: reference to 'rank' is ambiguous
   93 |                         v[rank[i].b].push_back(rank+i);
      |                           ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:93:48: error: reference to 'rank' is ambiguous
   93 |                         v[rank[i].b].push_back(rank+i);
      |                                                ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:94:29: error: reference to 'rank' is ambiguous
   94 |                         siz[rank[i].b]++;
      |                             ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:132:20: error: reference to 'rank' is ambiguous
  132 |                 sa[rank[i].a-1]=i;
      |                    ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:143:20: error: reference to 'rank' is ambiguous
  143 |                 if(rank[i].a==1)height[rank[i].a-1]=h[i]=0;
      |                    ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:143:40: error: reference to 'rank' is ambiguous
  143 |                 if(rank[i].a==1)height[rank[i].a-1]=h[i]=0;
      |                                        ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:145:32: error: reference to 'rank' is ambiguous
  145 |                         height[rank[i].a-1]=h[i]=mlcp(sa[rank[i].a-2],sa[rank[i].a-1]);
      |                                ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:145:58: error: reference to 'rank' is ambiguous
  145 |                         height[rank[i].a-1]=h[i]=mlcp(sa[rank[i].a-2],sa[rank[i].a-1]);
      |                                                          ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:145:74: error: reference to 'rank' is ambiguous
  145 |                         height[rank[i].a-1]=h[i]=mlcp(sa[rank[i].a-2],sa[rank[i].a-1]);
      |                                                                          ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:147:32: error: reference to 'rank' is ambiguous
  147 |                         height[rank[i].a-1]=h[i]=mlcp(sa[rank[i].a-2]+h[i-1]-2,sa[rank[i].a-1]+h[i-1]-2)+h[i-1]-2;
      |                                ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:147:58: error: reference to 'rank' is ambiguous
  147 |                         height[rank[i].a-1]=h[i]=mlcp(sa[rank[i].a-2]+h[i-1]-2,sa[rank[i].a-1]+h[i-1]-2)+h[i-1]-2;
      |                                                          ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~
a.cc:147:83: error: reference to 'rank' is ambiguous
  147 |                         height[rank[i].a-1]=h[i]=mlcp(sa[rank[i].a-2]+h[i-1]-2,sa[rank[i].a-1]+h[i-1]-2)+h[i-1]-2;
      |                                                                                   ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:2: note:                 'p rank [10004]'
   12 | }rank[10004];
      |  ^~~~