Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

class RollingHash{
private:
    const std::vector<int_fast64_t> base = {1007, 3001};
    const std::vector<int_fast64_t> mod = {1000000007, 1000000009};
    std::vector<int_fast64_t> hash[2], power[2];
public:
    RollingHash(){}
    RollingHash(const std::string& S){
        int_fast64_t len = S.length();
        for(int_fast64_t i = 0; i < 2; ++i){
            hash[i].assign(len+1, 0);
            power[i].assign(len+1, 1);
            for(int_fast64_t k = 0; k < len; ++k){
                hash[i][k+1] = (hash[i][k] * base[i] + S[k]) % mod[i];
                power[i][k+1] = (power[i][k] * base[i]) % mod[i];
            }
        }
    }
    
    inline std::pair<int_fast64_t,int_fast64_t> getHash(int_fast64_t l, int_fast64_t r) const {
        int_fast64_t res = hash[0][r] - hash[0][l] * power[0][r-l] % mod[0];
        if(res < 0) res += mod[0];
        int_fast64_t res1 = hash[1][r] - hash[1][l] * power[1][r-l] % mod[1];
        if(res < 0) res += mod[1];
        return {res, res1};
    }

    inline int_fast64_t LCP(RollingHash& RH, int_fast64_t l1, int_fast64_t l2) const {
        int_fast64_t len = hash[0].size();
        int_fast64_t high = std::min(len - l1, len - l2) + 1;
        int_fast64_t low = 0;
        while(high - low > 1){
            int_fast64_t mid = (high + low) >> 1;
            if(getHash(l1, l1 + mid) == RH.getHash(l2, l2 + mid)) low = mid;
            else high = mid;
        }
        return low;
    }
};

using namespace std;
int main(){
    int N;
    string S;
    cin >> N >> S;
    RollingHash A(S);
    using int = int_fast64_t;
    map<pair<int,int>, int> mp;
    
    auto check = [&](uint len) -> bool {
        for(int left=0;left+len<=N;left++){
            auto hashes = A.getHash(left, left+len);
            if(mp.count(hashes)){
                if(left - mp[hashes] >= len) return true;
            } else {
                mp[hashes] = left;
            }
        }
        return false;
    };

    int low = 0, high = N/2 + 1;
    while(high - low > 1){
        int mid = (low + high) >> 1;
        if(check(mid)) low = mid;
        else high = mid;
    }

    cout << low << endl;
}


Compiler output:
a.cc:8:23: error: 'int_fast64_t' was not declared in this scope
    8 |     const std::vector<int_fast64_t> base = {1007, 3001};
      |                       ^~~~~~~~~~~~
a.cc:8:35: error: template argument 1 is invalid
    8 |     const std::vector<int_fast64_t> base = {1007, 3001};
      |                                   ^
a.cc:8:35: error: template argument 2 is invalid
a.cc:9:23: error: 'int_fast64_t' was not declared in this scope
    9 |     const std::vector<int_fast64_t> mod = {1000000007, 1000000009};
      |                       ^~~~~~~~~~~~
a.cc:9:35: error: template argument 1 is invalid
    9 |     const std::vector<int_fast64_t> mod = {1000000007, 1000000009};
      |                                   ^
a.cc:9:35: error: template argument 2 is invalid
a.cc:10:17: error: 'int_fast64_t' was not declared in this scope
   10 |     std::vector<int_fast64_t> hash[2], power[2];
      |                 ^~~~~~~~~~~~
a.cc:10:29: error: template argument 1 is invalid
   10 |     std::vector<int_fast64_t> hash[2], power[2];
      |                             ^
a.cc:10:29: error: template argument 2 is invalid
a.cc:25:22: error: 'int_fast64_t' was not declared in this scope
   25 |     inline std::pair<int_fast64_t,int_fast64_t> getHash(int_fast64_t l, int_fast64_t r) const {
      |                      ^~~~~~~~~~~~
a.cc:25:35: error: 'int_fast64_t' was not declared in this scope
   25 |     inline std::pair<int_fast64_t,int_fast64_t> getHash(int_fast64_t l, int_fast64_t r) const {
      |                                   ^~~~~~~~~~~~
a.cc:25:47: error: template argument 1 is invalid
   25 |     inline std::pair<int_fast64_t,int_fast64_t> getHash(int_fast64_t l, int_fast64_t r) const {
      |                                               ^
a.cc:25:47: error: template argument 2 is invalid
a.cc:25:57: error: 'int_fast64_t' has not been declared
   25 |     inline std::pair<int_fast64_t,int_fast64_t> getHash(int_fast64_t l, int_fast64_t r) const {
      |                                                         ^~~~~~~~~~~~
a.cc:25:73: error: 'int_fast64_t' has not been declared
   25 |     inline std::pair<int_fast64_t,int_fast64_t> getHash(int_fast64_t l, int_fast64_t r) const {
      |                                                                         ^~~~~~~~~~~~
a.cc:33:12: error: 'int_fast64_t' does not name a type
   33 |     inline int_fast64_t LCP(RollingHash& RH, int_fast64_t l1, int_fast64_t l2) const {
      |            ^~~~~~~~~~~~
a.cc:8:55: error: cannot convert '<brace-enclosed initializer list>' to 'const int' in initialization
    8 |     const std::vector<int_fast64_t> base = {1007, 3001};
      |                                                       ^
a.cc:9:66: error: cannot convert '<brace-enclosed initializer list>' to 'const int' in initialization
    9 |     const std::vector<int_fast64_t> mod = {1000000007, 1000000009};
      |                                                                  ^
a.cc: In constructor 'RollingHash::RollingHash(const std::string&)':
a.cc:14:9: error: 'int_fast64_t' was not declared in this scope
   14 |         int_fast64_t len = S.length();
      |         ^~~~~~~~~~~~
a.cc:15:26: error: expected ';' before 'i'
   15 |         for(int_fast64_t i = 0; i < 2; ++i){
      |                          ^
a.cc:15:33: error: 'i' was not declared in this scope
   15 |         for(int_fast64_t i = 0; i < 2; ++i){
      |                                 ^
a.cc:16:28: error: 'len' was not declared in this scope; did you mean 'mblen'?
   16 |             hash[i].assign(len+1, 0);
      |                            ^~~
      |                            mblen
a.cc:18:30: error: expected ';' before 'k'
   18 |             for(int_fast64_t k = 0; k < len; ++k){
      |                              ^
a.cc:18:37: error: 'k' was not declared in this scope
   18 |             for(int_fast64_t k = 0; k < len; ++k){
      |                                     ^
a.cc: In member function 'int RollingHash::getHash(int, int) const':
a.cc:26:9: error: 'int_fast64_t' was not declared in this scope
   26 |         int_fast64_t res = hash[0][r] - hash[0][l] * power[0][r-l] % mod[0];
      |         ^~~~~~~~~~~~
a.cc:27:12: error: 'res' was not declared in this scope
   27 |         if(res < 0) res += mod[0];
      |            ^~~
a.cc:27:31: error: invalid types 'const int[int]' for array subscript
   27 |         if(res < 0) res += mod[0];
      |                               ^
a.cc:28:22: error: expected ';' before 'res1'
   28 |         int_fast64_t res1 = hash[1][r] - hash[1][l] * power[1][r-l] % mod[1];
      |                      ^~~~
a.cc:29:12: error: 'res' was not declared in this scope
   29 |         if(res < 0) res += mod[1];
      |            ^~~
a.cc:29:31: error: invalid types 'const int[int]' for array subscript
   29 |         if(res < 0) res += mod[1];
      |                               ^
a.cc:30:17: error: 'res' was not declared in this scope
   30 |         return {res, res1};
      |                 ^~~
a.cc:30:22: error: 'res1' was not declared in this scope
   30 |         return {res, res1};
      |                      ^~~~
a.cc:30:26: error: cannot convert '<brace-enclosed initializer list>' to 'int' in return
   30 |         return {res, res1};
      |                          ^
a.cc: In function 'int main()':
a.cc:52:11: error: expected nested-name-specifier before 'int'
   52 |     using int = int_fast64_t;
      |           ^~~
a.cc: In lambda function:
a.cc:58:24: error: no matching function for call to 'std::map<std::pair<int, int>, int>::count(int&)'
   58 |             if(mp.count(hashes)){
      |                ~~~~~~~~^~~~~~~~
In file included from /usr/include/c++/14/map:63,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_map.h:1270:9: note: candidate: 'template<class _Kt> decltype (((const std::map<_Key, _Tp, _Compare, _Alloc>*)this)->std::map<_Key, _Tp, _Compare, _Alloc>::_M_t._M_count_tr(__x)) std::map<_Key, _Tp, _Compare, _Alloc>::count(const _Kt&) const [with _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]'
 1270 |         count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
      |         ^~~~~
/usr/include/c++/14/bits/stl_map.h:1270:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_map.h: In substitution of 'template<class _Kt> decltype (((const std::map<std::pair<int, int>, int>*)this)->std::map<std::pair<int, int>, int>::_M_t.std::_Rb_tree<std::pair<int, int>, std::pair<const std::pair<int, int>, int>, std::_Select1st<std::pair<const std::pair<int, int>, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<const std::pair<int, int>, int> > >::_M_count_tr<_Kt, _Req>(__x)) std::map<std::pair<int, int>, int>::count(const _Kt&) const [with _Kt = int]':
a.cc:58:24:   required from here
   58 |             if(mp.count(hashes)){
      |                ~~~~~~~~^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:1270:65: error: no matching function for call to 'std::_Rb_tree<std::pair<int, int>, std::pair<const std::pair<int, int>, int>, std::_Select1st<std::pair<const std::pair<int, int>, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<const std::pair<int, int>, int> > >::_M_count_tr(const int&) const'
 1270 |         count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
      |                                                 ~~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/map:62:
/usr/include/c++/14/bits/stl_tree.h:1311:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_count_tr(const _Kt&) const [with _Req = _Kt; _Key = std::pair<int, int>; _Val = std::pair<const std::pair<int, int>, int>; _KeyOfValue = std::_Select1st<std::pair<const std::pair<int, int>, int> >; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]'
 1311 |         _M_count_tr(const _Kt& __k) const
      |         ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1311:9: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/14/string:49,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_function.h: In substitution of 'template<class _Func, class _SfinaeType> using std::__has_is_transparent_t = typename std::__has_is_transparent<_Func, _SfinaeType>::type [with _Func = std::less<std::pair<int, int> >; _SfinaeType = int]':
/usr/include/c++/14/bits/stl_tree.h:1309:9:   required by substitution of 'template<class _Kt> decltype (((const std::map<std::pair<int, int>, int>*)this)->std::map<std::pair<int, int>, int>::_M_t.std::_Rb_tree<std::pair<int, int>, std::pair<const std::pair<int, int>, int>, std::_Select1st<std::pair<const std::pair<int, int>, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<const std::pair<int, int>, int> > >::_M_count_tr<_Kt, _Req>(__x)) std::map<std::pair<int, int>, int>::count(const _Kt&) const [with _Kt = int]'
 1309 |                typename _Req = __has_is_transparent_t<_Compare, _Kt>>
      |                ^~~~~~~~
a.cc:58:24:   required from here
   58 |             if(mp.count(hashes)){
      |                ~~~~~~~~^~~~~~~~
/usr/include/c++/14/bits/stl_function.h:1427:11: error: no type named 'type' in 'struct std::__has_is_transparent<std::less<std::pair<int, int> >, int, void>'
 1427 |     using __has_is_transparent_t
      |           ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_map.h:1264:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::size_type std::map<_Key, _Tp, _Compare, _Alloc>::count(const key_type&) const [with _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _