Language: C++

/*
 * atcoder/abc125/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/* セグメントツリー */
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;
  }
};
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int N;

void solve() {
  cin >> N;
  int a;
  SegTree<int> seg(N, [](int a, int b) { return gcd(a, b); }, 0);
  loop(n,0,N) {
    cin >> a;
    seg.set(n, a);
  }
  seg.build();

  int max_ = 0;
  loop(n,0,N) {
    chmax(max_, gcd(seg.get(0, n), seg.get(n+1, N)));
  }

  cout << max_ << endl;
}

int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


Compiler output:
a.cc:20:16: error: 'function' does not name a type; did you mean 'union'?
   20 |   using Func = function<Monoid(Monoid, Monoid)>;
      |                ^~~~~~~~
      |                union
a.cc:21:9: error: 'Func' does not name a type
   21 |   const Func F;
      |         ^~~~
a.cc:26:24: error: 'Func' does not name a type
   26 |   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:26:54: error: class 'SegTree<Monoid>' does not have any field named 'F'
   26 |   SegTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) { init(n); }
      |                                                      ^
a.cc: In function 'void solve()':
a.cc:74:23: error: invalid user-defined conversion from 'solve()::<lambda(int, int)>' to 'int' [-fpermissive]
   74 |   SegTree<int> seg(N, [](int a, int b) { return gcd(a, b); }, 0);
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:74:23: note: candidate is: 'constexpr solve()::<lambda(int, int)>::operator int (*)(int, int)() const' (near match)
   74 |   SegTree<int> seg(N, [](int a, int b) { return gcd(a, b); }, 0);
      |                       ^
a.cc:74:23: note:   no known conversion from 'int (*)(int, int)' to 'int'
a.cc:26:29: note:   initializing argument 2 of 'SegTree<Monoid>::SegTree(int, int, const Monoid&) [with Monoid = int]'
   26 |   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 = int]':
a.cc:79:12:   required from here
   79 |   seg.build();
      |   ~~~~~~~~~^~
a.cc:37:17: error: 'F' was not declared in this scope
   37 |       dat[k] = F(dat[k*2], dat[k*2+1]);
      |                ~^~~~~~~~~~~~~~~~~~~~~~
a.cc: In instantiation of 'Monoid SegTree<Monoid>::get(int, int) [with Monoid = int]':
a.cc:83:28:   required from here
   83 |     chmax(max_, gcd(seg.get(0, n), seg.get(n+1, N)));
      |                     ~~~~~~~^~~~~~
a.cc:51:30: error: 'F' was not declared in this scope
   51 |       if (left & 1) vleft = F(vleft, dat[left++]);
      |                             ~^~~~~~~~~~~~~~~~~~~~
a.cc:52:32: error: 'F' was not declared in this scope
   52 |       if (right & 1) vright = F(dat[--right], vright);
      |                               ~^~~~~~~~~~~~~~~~~~~~~~
a.cc:54:13: error: 'F' was not declared in this scope
   54 |     return F(vleft, vright);
      |            ~^~~~~~~~~~~~~~~