Language: C++

#include <iostream>
#include <vector>
#include <bits/stdc++.h>

using namespace std;

int n , k;
int rank[100010],rank2[100010];
int tmp[100010];

bool compare_sa(int i , int j){
  if(rank[i] != rank[j]) return rank[i] < rank[j];
  else{
    int ri = i + k <= n ? rank[i+k] : -1;
    int rj = j + k <= n ? rank[j+k] : -1;
    return ri < rj;
  }
}

void construct_sa(string S , int *sa){
  n = S.length();
  
  for(int i=0;i<=n;i++){
    sa[i] = i;
    rank[i] = i < n ? S[i] : -1;
  }
  
  for(k=1;k<=n;k*=2){
    sort(sa, sa+n+1,compare_sa);
    
    tmp[sa[0]] = 0;
    for(int i=1;i<=n;i++){
      tmp[sa[i]] = tmp[sa[i-1]] + (compare_sa(sa[i-1], sa[i]) ? 1 : 0);
    }
    for(int i = 0;i<=n;i++){
      rank[i] = tmp[i];
    }
  }
}

void construct_lcp(string S ,int *sa , int *lcp){
  int m = S.length();
  for(int i=0;i<=m;i++) rank[sa[i]] = i;
  
  int h = 0;
  lcp[0] = 0;
  for(int i=0;i<m;i++){
    int j = sa[rank[i]-1];
    
    if(h>0) h--;
    for(; j+h<n && i+h<n;h++){
      if(S[j+h] != S[i+h]) break;
    }
    
    lcp[rank[i] - 1] = h;
  }
}
int a;
string s;
int sa1[100010],lcp1[100010];


int main(){
  cin >> a ;
  cin >> s ;
  
  construct_sa(s,sa1);
  construct_lcp(s,sa1,lcp1);
  
  int ans = 0;
  
  for(int i=0;i< a;i++){
    for(int j=i+1;j<a;j++){
    if((sa1[i] < a) != (sa1[i+1] < a)){
      lcp1[i] = min(lcp1[i],j-i);
      ans = max(ans , lcp1[i]);
    }
  }
  }
  cout << ans << endl;
}
    


Compiler output:
a.cc: In function 'bool compare_sa(int, int)':
a.cc:12:6: error: reference to 'rank' is ambiguous
   12 |   if(rank[i] != rank[j]) return rank[i] < rank[j];
      |      ^~~~
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:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:5: note:                 'int rank [100010]'
    8 | int rank[100010],rank2[100010];
      |     ^~~~
a.cc:12:17: error: reference to 'rank' is ambiguous
   12 |   if(rank[i] != rank[j]) return rank[i] < rank[j];
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:5: note:                 'int rank [100010]'
    8 | int rank[100010],rank2[100010];
      |     ^~~~
a.cc:12:33: error: reference to 'rank' is ambiguous
   12 |   if(rank[i] != rank[j]) return rank[i] < rank[j];
      |                                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:5: note:                 'int rank [100010]'
    8 | int rank[100010],rank2[100010];
      |     ^~~~
a.cc:12:43: error: reference to 'rank' is ambiguous
   12 |   if(rank[i] != rank[j]) return rank[i] < rank[j];
      |                                           ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:5: note:                 'int rank [100010]'
    8 | int rank[100010],rank2[100010];
      |     ^~~~
a.cc:14:27: error: reference to 'rank' is ambiguous
   14 |     int ri = i + k <= n ? rank[i+k] : -1;
      |                           ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:5: note:                 'int rank [100010]'
    8 | int rank[100010],rank2[100010];
      |     ^~~~
a.cc:15:27: error: reference to 'rank' is ambiguous
   15 |     int rj = j + k <= n ? rank[j+k] : -1;
      |                           ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:5: note:                 'int rank [100010]'
    8 | int rank[100010],rank2[100010];
      |     ^~~~
a.cc: In function 'void construct_sa(std::string, int*)':
a.cc:25:5: error: reference to 'rank' is ambiguous
   25 |     rank[i] = i < n ? S[i] : -1;
      |     ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:5: note:                 'int rank [100010]'
    8 | int rank[100010],rank2[100010];
      |     ^~~~
a.cc:36:7: error: reference to 'rank' is ambiguous
   36 |       rank[i] = tmp[i];
      |       ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:5: note:                 'int rank [100010]'
    8 | int rank[100010],rank2[100010];
      |     ^~~~
a.cc: In function 'void construct_lcp(std::string, int*, int*)':
a.cc:43:25: error: reference to 'rank' is ambiguous
   43 |   for(int i=0;i<=m;i++) rank[sa[i]] = i;
      |                         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:5: note:                 'int rank [100010]'
    8 | int rank[100010],rank2[100010];
      |     ^~~~
a.cc:48:16: error: reference to 'rank' is ambiguous
   48 |     int j = sa[rank[i]-1];
      |                ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:5: note:                 'int rank [100010]'
    8 | int rank[100010],rank2[100010];
      |     ^~~~
a.cc:55:9: error: reference to 'rank' is ambiguous
   55 |     lcp[rank[i] - 1] = h;
      |         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:5: note:                 'int rank [100010]'
    8 | int rank[100010],rank2[100010];
      |     ^~~~