Language: C++

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>

using namespace std;
typedef long long ll;

template<class Monoid> struct SegTree {
  using Func = function<Monoid(Monoid, Monoid)>;
  const Func F;
  const Monoid UNITY;
  int SIZE_R;
  vector<Monoid> dat;
  
  SegTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) { init(n); }
  void init(int n) {
    SIZE_R = 1;
    while (SIZE_R < n) SIZE_R *= 2;
    dat.assign(SIZE_R * 2, UNITY);
  }
  
  /* set, a is 0-indexed */
  void set(int a, const Monoid &v) { dat[a + SIZE_R] = v; }
  void build() {
    for (int k = SIZE_R - 1; k > 0; --k)
      dat[k] = F(dat[k*2], dat[k*2+1]);
  }
  
  /* update a, a is 0-indexed */
  void update(int a, const Monoid &v) {
    int k = a + SIZE_R;
    dat[k] = v;
    while (k >>= 1) dat[k] = F(dat[k*2], dat[k*2+1]);
  }
  
  /* get [a, b), a and b are 0-indexed */
  Monoid get(int a, int b) {
    Monoid vleft = UNITY, vright = UNITY;
    for (int left = a + SIZE_R, right = b + SIZE_R; left < right; left >>= 1, right >>= 1) {
      if (left & 1) vleft = F(vleft, dat[left++]);
      if (right & 1) vright = F(dat[--right], vright);
    }
    return F(vleft, vright);
  }
  inline Monoid operator [] (int a) { return dat[a + SIZE_R]; }
  
  /* debug */
  void print() {
    for (int i = 0; i < SIZE_R; ++i) {
      cout << (*this)[i];
      if (i != SIZE_R-1) cout << ",";
    }
    cout << endl;
  }
};

long long GCD(long long a, long long b) {
  return b ? GCD(b, a%b) : a;
}

int main(int argc, const char * argv[]) {
  int n;
  cin >> n;

  SegTree<ll> seg(n, [](ll a, ll b) {
    return GCD(a, b);
  }, 0);
  
  vector<ll> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
    seg.set(i, vec[i]);
  }
  seg.build();
  
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll left = seg.get(0, i);
    ll right = seg.get(i + 1, n);
    ans = max(ans, GCD(left, right));
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc:19:16: error: 'function' does not name a type; did you mean 'union'?
   19 |   using Func = function<Monoid(Monoid, Monoid)>;
      |                ^~~~~~~~
      |                union
a.cc:20:9: error: 'Func' does not name a type
   20 |   const Func F;
      |         ^~~~
a.cc:25:24: error: 'Func' does not name a type
   25 |   SegTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) { init(n); }
      |                        ^~~~
a.cc: In constructor 'SegTree<Monoid>::SegTree(int, int, const Monoid&)':
a.cc:25:54: error: class 'SegTree<Monoid>' does not have any field named 'F'
   25 |   SegTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) { init(n); }
      |                                                      ^
a.cc: In function 'int main(int, const char**)':
a.cc:75:22: error: invalid user-defined conversion from 'main(int, const char**)::<lambda(ll, ll)>' to 'int' [-fpermissive]
   75 |   SegTree<ll> seg(n, [](ll a, ll b) {
      |                      ^~~~~~~~~~~~~~~~
   76 |     return GCD(a, b);
      |     ~~~~~~~~~~~~~~~~~ 
   77 |   }, 0);
      |   ~                   
a.cc:75:22: note: candidate is: 'constexpr main(int, const char**)::<lambda(ll, ll)>::operator long long int (*)(ll, ll)() const' (near match)
   75 |   SegTree<ll> seg(n, [](ll a, ll b) {
      |                      ^
a.cc:75:22: note:   no known conversion from 'long long int (*)(ll, ll)' {aka 'long long int (*)(long long int, long long int)'} to 'int'
a.cc:25:29: note:   initializing argument 2 of 'SegTree<Monoid>::SegTree(int, int, const Monoid&) [with Monoid = long long int]'
   25 |   SegTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) { init(n); }
      |                  ~~~~~~~~~~~^
a.cc: In instantiation of 'void SegTree<Monoid>::build() [with Monoid = long long int]':
a.cc:84:12:   required from here
   84 |   seg.build();
      |   ~~~~~~~~~^~
a.cc:36:17: error: 'F' was not declared in this scope
   36 |       dat[k] = F(dat[k*2], dat[k*2+1]);
      |                ~^~~~~~~~~~~~~~~~~~~~~~
a.cc: In instantiation of 'Monoid SegTree<Monoid>::get(int, int) [with Monoid = long long int]':
a.cc:88:22:   required from here
   88 |     ll left = seg.get(0, i);
      |               ~~~~~~~^~~~~~
a.cc:50:30: error: 'F' was not declared in this scope
   50 |       if (left & 1) vleft = F(vleft, dat[left++]);
      |                             ~^~~~~~~~~~~~~~~~~~~~
a.cc:51:32: error: 'F' was not declared in this scope
   51 |       if (right & 1) vright = F(dat[--right], vright);
      |                               ~^~~~~~~~~~~~~~~~~~~~~~
a.cc:53:13: error: 'F' was not declared in this scope
   53 |     return F(vleft, vright);
      |            ~^~~~~~~~~~~~~~~