Language: C++

#include <climits>
#include <functional>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
template <typename T, typename E>
struct SegmentTree {
	typedef function<T(T, T)> F;
	typedef function<T(T, E)> G;
	int n;
	F f;
	G g;
	T d1;
	E d0;
	vector<T> dat;
	SegmentTree(){};
	SegmentTree(int n_, F f, G g, T d1, vector<T> v = vector<T>()) : f(f), g(g), d1(d1) {
		init(n_);
		if (n_ == (int)v.size()) build(n_, v);
	}
	void init(int n_) {
		n = 1;
		while (n < n_) n *= 2;
		dat.clear();
		dat.resize(2 * n - 1, d1);
	}
	void build(int n_, vector<T> v) {
		for (int i = 0; i < n_; i++) dat[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
	}
	void update(int k, E a) {
		k += n - 1;
		dat[k] = g(dat[k], a);
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	inline T query(int a, int b) {
		T vl = d1, vr = d1;
		for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
			if (l & 1) vl = f(vl, dat[(l++) - 1]);
			if (r & 1) vr = f(dat[(--r) - 1], vr);
		}
		return f(vl, vr);
	}
};
int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i, n) cin >> v[i];
	SegmentTree<int, int> gcdq(
	    n, [](int a, int b) { return __gcd(a, b); }, [](int a, int b) { return b; }, 0, v);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		gcdq.update(i, 0);
		ans = max(ans, gcdq.dat[0]);
		gcdq.update(i, v[i]);
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In lambda function:
a.cc:59:42: error: '__gcd' was not declared in this scope; did you mean 'std::__detail::__gcd'?
   59 |             n, [](int a, int b) { return __gcd(a, b); }, [](int a, int b) { return b; }, 0, v);
      |                                          ^~~~~
      |                                          std::__detail::__gcd
In file included from a.cc:4:
/usr/include/c++/14/numeric:134:5: note: 'std::__detail::__gcd' declared here
  134 |     __gcd(_Tp __m, _Tp __n)
      |     ^~~~~
a.cc: In function 'int main()':
a.cc:59:94: error: no matching function for call to 'SegmentTree<int, int>::SegmentTree(int&, main()::<lambda(int, int)>, main()::<lambda(int, int)>, int, std::vector<int>&)'
   59 |             n, [](int a, int b) { return __gcd(a, b); }, [](int a, int b) { return b; }, 0, v);
      |                                                                                              ^
a.cc:20:9: note: candidate: 'SegmentTree<T, E>::SegmentTree(int, F, G, T, std::vector<T>) [with T = int; E = int; F = std::function<int(int, int)>; G = std::function<int(int, int)>]'
   20 |         SegmentTree(int n_, F f, G g, T d1, vector<T> v = vector<T>()) : f(f), g(g), d1(d1) {
      |         ^~~~~~~~~~~
a.cc:20:31: note:   no known conversion for argument 2 from 'main()::<lambda(int, int)>' to 'SegmentTree<int, int>::F' {aka 'std::function<int(int, int)>'}
   20 |         SegmentTree(int n_, F f, G g, T d1, vector<T> v = vector<T>()) : f(f), g(g), d1(d1) {
      |                             ~~^
a.cc:19:9: note: candidate: 'SegmentTree<T, E>::SegmentTree() [with T = int; E = int]'
   19 |         SegmentTree(){};
      |         ^~~~~~~~~~~
a.cc:19:9: note:   candidate expects 0 arguments, 5 provided
a.cc:10:8: note: candidate: 'SegmentTree<int, int>::SegmentTree(const SegmentTree<int, int>&)'
   10 | struct SegmentTree {
      |        ^~~~~~~~~~~
a.cc:10:8: note:   candidate expects 1 argument, 5 provided
a.cc:10:8: note: candidate: 'SegmentTree<int, int>::SegmentTree(SegmentTree<int, int>&&)'
a.cc:10:8: note:   candidate expects 1 argument, 5 provided