Language: C++

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
using namespace std;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }
};

int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

int main()
{
  int N;
  cin>>N;
  SegmentTree< int > seg(N, [](int a, int b) { return gcd(a, b); }, 0);
  for(int i=1;i<=N;i++){
    int a;cin>>a;
    seg.update(i,a);
  }
  int ans=max(seg.query(2,N+1),seg.query(1,N));
  for(int i=2;i<N;i++){
    ans=max(gcd(seg.query(1,i),seg.query(i+1,N+1)),ans);
  }
  cout<<ans<<endl;
}


Compiler output:
a.cc:14:13: error: 'function' does not name a type; did you mean 'union'?
   14 |   using F = function< Monoid(Monoid, Monoid) >;
      |             ^~~~~~~~
      |             union
a.cc:19:9: error: 'F' does not name a type
   19 |   const F f;
      |         ^
a.cc:22:28: error: 'F' does not name a type
   22 |   SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
      |                            ^
a.cc: In constructor 'SegmentTree<Monoid>::SegmentTree(int, int, const Monoid&)':
a.cc:22:53: error: class 'SegmentTree<Monoid>' does not have any field named 'f'
   22 |   SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
      |                                                     ^
a.cc: In function 'int main()':
a.cc:71:29: error: invalid user-defined conversion from 'main()::<lambda(int, int)>' to 'int' [-fpermissive]
   71 |   SegmentTree< int > seg(N, [](int a, int b) { return gcd(a, b); }, 0);
      |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:71:29: note: candidate is: 'constexpr main()::<lambda(int, int)>::operator int (*)(int, int)() const' (near match)
   71 |   SegmentTree< int > seg(N, [](int a, int b) { return gcd(a, b); }, 0);
      |                             ^
a.cc:71:29: note:   no known conversion from 'int (*)(int, int)' to 'int'
a.cc:22:30: note:   initializing argument 2 of 'SegmentTree<Monoid>::SegmentTree(int, int, const Monoid&) [with Monoid = int]'
   22 |   SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
      |                      ~~~~~~~~^
a.cc: In instantiation of 'void SegmentTree<Monoid>::update(int, const Monoid&) [with Monoid = int]':
a.cc:74:15:   required from here
   74 |     seg.update(i,a);
      |     ~~~~~~~~~~^~~~~
a.cc:42:17: error: 'f' was not declared in this scope
   42 |       seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
      |                ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In instantiation of 'Monoid SegmentTree<Monoid>::query(int, int) [with Monoid = int]':
a.cc:76:24:   required from here
   76 |   int ans=max(seg.query(2,N+1),seg.query(1,N));
      |               ~~~~~~~~~^~~~~~~
a.cc:49:22: error: 'f' was not declared in this scope
   49 |       if(a & 1) L = f(L, seg[a++]);
      |                     ~^~~~~~~~~~~~~
a.cc:50:22: error: 'f' was not declared in this scope
   50 |       if(b & 1) R = f(seg[--b], R);
      |                     ~^~~~~~~~~~~~~
a.cc:52:13: error: 'f' was not declared in this scope
   52 |     return f(L, R);
      |            ~^~~~~~