Language: C++

#include <bits/stdc++.h>

template <typename T>
class SegmentTree
{
private:
  using Fn = function<T(T, T)>;
  int N;
  vector<T> dat;
  T unit;
  Fn func;

public:
  SegmentTree() {}
  SegmentTree(int n_, Fn func_, T unit_) : func(func_), unit(unit_)
  {
    N = 1;
    while (N < n_)
      N *= 2;
    dat.assign(2 * N - 1, unit);
  }
  SegmentTree(const vector<T> &v, Fn func_, T unit_) : func(func_), unit(unit_)
  {
    N = 1;
    int sz = v.size();
    while (N < sz)
      N *= 2;
    dat.resize(2 * N - 1);
    for (int i = 0; i < N; ++i)
      dat[i + N - 1] = (i < sz ? v[i] : unit);
    for (int i = N - 2; i >= 0; --i)
      dat[i] = func(dat[i * 2 + 1], dat[i * 2 + 2]);
  }

  // k 番目の要素を a に変更
  void update(int k, T a)
  {
    k += N - 1;
    dat[k] = a;
    while (k > 0)
    {
      k = (k - 1) / 2;
      dat[k] = func(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  // k 番目の要素を取得
  T get(int k) { return dat[k + N - 1]; }

  // 区間 [l, r) の和を取得
  T query(int l, int r)
  {
    T vl = unit, vr = unit;
    for (l += (N - 1), r += (N - 1); l < r; l >>= 1, r >>= 1)
    {
      if ((l & 1) == 0)
        vl = func(vl, dat[l]);
      if ((r & 1) == 0)
        vr = func(vr, dat[--r]);
    }
    return func(vl, vr);
  }

#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
  
  ll gcd(ll m, ll n) {//最大公約数
    if (n == 0)return m;
    return gcd(n, m % n);
}//gcd

int main(){
    ll n;
    cin>>n;
    auto big = [](ll a, ll b) { return gcd(a, b); };
    SegmentTree<ll> sgt(n, big, 0);
    for (ll i = 0; i < n; i++) {
        ll t;
        cin>>t;
        sgt.update(i,t);
    }
    ll ans = 0;
    for (ll i=0;i<n;i++) {
        ll kotae=gcd(sgt.query(0, i), sgt.query(i, n));
        chmax(ans,kotae);
    }
    cout<<ans<<endl;


Compiler output:
a.cc:7:14: error: 'function' does not name a type; did you mean 'union'?
    7 |   using Fn = function<T(T, T)>;
      |              ^~~~~~~~
      |              union
a.cc:9:3: error: 'vector' does not name a type
    9 |   vector<T> dat;
      |   ^~~~~~
a.cc:11:3: error: 'Fn' does not name a type
   11 |   Fn func;
      |   ^~
a.cc:15:23: error: 'Fn' has not been declared
   15 |   SegmentTree(int n_, Fn func_, T unit_) : func(func_), unit(unit_)
      |                       ^~
a.cc:22:21: error: 'vector' does not name a type
   22 |   SegmentTree(const vector<T> &v, Fn func_, T unit_) : func(func_), unit(unit_)
      |                     ^~~~~~
a.cc:22:27: error: expected ',' or '...' before '<' token
   22 |   SegmentTree(const vector<T> &v, Fn func_, T unit_) : func(func_), unit(unit_)
      |                           ^
a.cc:66:7: error: expected nested-name-specifier before 'namespace'
   66 | using namespace std;
      |       ^~~~~~~~~
a.cc:88:21: error: expected '}' at end of input
   88 |     cout<<ans<<endl;
      |                     ^
a.cc:5:1: note: to match this '{'
    5 | {
      | ^
a.cc: In constructor 'SegmentTree<T>::SegmentTree(int, int, T)':
a.cc:15:44: error: class 'SegmentTree<T>' does not have any field named 'func'
   15 |   SegmentTree(int n_, Fn func_, T unit_) : func(func_), unit(unit_)
      |                                            ^~~~
a.cc:20:5: error: 'dat' was not declared in this scope
   20 |     dat.assign(2 * N - 1, unit);
      |     ^~~
a.cc: In constructor 'SegmentTree<T>::SegmentTree(int)':
a.cc:22:56: error: class 'SegmentTree<T>' does not have any field named 'func'
   22 |   SegmentTree(const vector<T> &v, Fn func_, T unit_) : func(func_), unit(unit_)
      |                                                        ^~~~
a.cc:22:61: error: 'func_' was not declared in this scope
   22 |   SegmentTree(const vector<T> &v, Fn func_, T unit_) : func(func_), unit(unit_)
      |                                                             ^~~~~
a.cc:22:74: error: 'unit_' was not declared in this scope; did you mean 'unit'?
   22 |   SegmentTree(const vector<T> &v, Fn func_, T unit_) : func(func_), unit(unit_)
      |                                                                          ^~~~~
      |                                                                          unit
a.cc:25:14: error: 'v' was not declared in this scope
   25 |     int sz = v.size();
      |              ^
a.cc:28:5: error: 'dat' was not declared in this scope
   28 |     dat.resize(2 * N - 1);
      |     ^~~
a.cc:32:16: error: there are no arguments to 'func' that depend on a template parameter, so a declaration of 'func' must be available [-fpermissive]
   32 |       dat[i] = func(dat[i * 2 + 1], dat[i * 2 + 2]);
      |                ^~~~
a.cc:32:16: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc: In member function 'void SegmentTree<T>::update(int, T)':
a.cc:39:5: error: 'dat' was not declared in this scope
   39 |     dat[k] = a;
      |     ^~~
a.cc:43:16: error: there are no arguments to 'func' that depend on a template parameter, so a declaration of 'func' must be available [-fpermissive]
   43 |       dat[k] = func(dat[k * 2 + 1], dat[k * 2 + 2]);
      |                ^~~~
a.cc: In member function 'T SegmentTree<T>::get(int)':
a.cc:48:25: error: 'dat' was not declared in this scope
   48 |   T get(int k) { return dat[k + N - 1]; }
      |                         ^~~
a.cc: In member function 'T SegmentTree<T>::query(int, int)':
a.cc:57:23: error: 'dat' was not declared in this scope
   57 |         vl = func(vl, dat[l]);
      |                       ^~~
a.cc:59:23: error: 'dat' was not declared in this scope
   59 |         vr = func(vr, dat[--r]);
      |                       ^~~
a.cc: In member function 'int SegmentTree<T>::main()':
a.cc:75:5: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   75 |     cin>>n;
      |     ^~~
      |     std::cin
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:146,
                 from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:86:9: error: there are no arguments to 'chmax' that depend on a template parameter, so a declaration of 'chmax' must be available [-fpermissive]
   86 |         chmax(ans,kotae);
      |         ^~~~~
a.cc:88:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   88 |     cout<<ans<<endl;
      |     ^~~~
      |     std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:88:16: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   88 |     cout<<ans<<endl;
      |                ^~~~
      |                std::endl
In file included from /usr/include/c++/14/istream:41,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc:88:21: error: expected '}' at end of input
   88 |     cout<<ans<<endl;
      |                     ^
a.cc:73:11: note: to match this '{'
   73 | int main(){
      |           ^
a.cc: At global scope:
a.cc:88:21: error: expected ';' at end of input
   88 |     cout<<ans<<endl;
      |                     ^
      |                     ;