Language: C++

#include <vector>
#include <cmath>
#include <limits>
#include <iostream>

template<typename T>
class Segtree{
  int nbin;
  T param_def;
  std::vector<T> seg_vec;
  std::function<T(T, T)> seg_func;
  T segtree_query_partial(int a, int b, int k, int l, int r){
    if(r <= a || b <= l) return param_def;
    if(a <= l && r <= b) return seg_vec[k];
    const T v_l = segtree_query_partial(a, b, k*2+1, l, (l+r)/2);
    const T v_r = segtree_query_partial(a, b, k*2+2, (l+r)/2, r);
    return seg_func(v_l, v_r);
  }
  auto max_bit(int32_t n){
    n = n & 0xFFFF0000 ? n & 0xFFFF0000 : n;
    n = n & 0xFF00FF00 ? n & 0xFF00FF00 : n;
    n = n & 0xF0F0F0F0 ? n & 0xF0F0F0F0 : n;
    n = n & 0xCCCCCCCC ? n & 0xCCCCCCCC : n;
    n = n & 0xAAAAAAAA ? n & 0xAAAAAAAA : n;
    return n;
  }
  public:
  Segtree(const std::vector<T>& data, const std::function<T(T, T)>& _seg_func, const T _param_def) :
    seg_func(_seg_func), param_def(_param_def) {
      nbin = max_bit(data.size()-1)*2;
      seg_vec.resize(nbin*2-1, param_def);
      auto insert_top = seg_vec.begin();
      insert_top += nbin-1;
      std::copy(data.cbegin(), data.cend(), insert_top);
      for(int i = nbin-2; i >= 0; i--){
        seg_vec[i] = seg_func(seg_vec[i*2+1], seg_vec[i*2+2]);
      }
    }
  void update(int i, int x){
    i += nbin-1;
    seg_vec[i] = x;
    while(i > 0){
      i = (i-1)/2;
      seg_vec[i] = seg_func(seg_vec[i*2+1], seg_vec[i*2+2]);
    }
  }
  T query(int a, int b){
    return segtree_query_partial(a, b, 0, 0, nbin);
  }
};

int main(){
  int N;
  std::cin >> N;
  std::vector<int>A_arr(N);
  for(int i = 0; i < N; i++){
    std::cin >> A_arr[i];
  }

  Segtree<int> seg(A_arr, [](int l, int r){return std::max(l, r);}, -1);
  for(int i = 0; i < N; i++){
    std::cout << std::max(seg.query(0, i), seg.query(i+1, N)) << "\n";
  }

  return 0;
}




Compiler output:
a.cc:11:8: error: 'function' in namespace 'std' does not name a template type
   11 |   std::function<T(T, T)> seg_func;
      |        ^~~~~~~~
a.cc:5:1: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>'
    4 | #include <iostream>
  +++ |+#include <functional>
    5 | 
a.cc:28:50: error: 'function' in namespace 'std' does not name a template type
   28 |   Segtree(const std::vector<T>& data, const std::function<T(T, T)>& _seg_func, const T _param_def) :
      |                                                  ^~~~~~~~
a.cc:28:45: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>'
   28 |   Segtree(const std::vector<T>& data, const std::function<T(T, T)>& _seg_func, const T _param_def) :
      |                                             ^~~
a.cc:28:58: error: expected ',' or '...' before '<' token
   28 |   Segtree(const std::vector<T>& data, const std::function<T(T, T)>& _seg_func, const T _param_def) :
      |                                                          ^
a.cc: In constructor 'Segtree<T>::Segtree(const std::vector<T>&, int)':
a.cc:29:5: error: class 'Segtree<T>' does not have any field named 'seg_func'
   29 |     seg_func(_seg_func), param_def(_param_def) {
      |     ^~~~~~~~
a.cc:29:14: error: '_seg_func' was not declared in this scope
   29 |     seg_func(_seg_func), param_def(_param_def) {
      |              ^~~~~~~~~
a.cc:29:36: error: '_param_def' was not declared in this scope; did you mean 'param_def'?
   29 |     seg_func(_seg_func), param_def(_param_def) {
      |                                    ^~~~~~~~~~
      |                                    param_def
a.cc: In function 'int main()':
a.cc:60:71: error: no matching function for call to 'Segtree<int>::Segtree(std::vector<int>&, main()::<lambda(int, int)>, int)'
   60 |   Segtree<int> seg(A_arr, [](int l, int r){return std::max(l, r);}, -1);
      |                                                                       ^
a.cc:28:3: note: candidate: 'Segtree<T>::Segtree(const std::vector<T>&, int) [with T = int]'
   28 |   Segtree(const std::vector<T>& data, const std::function<T(T, T)>& _seg_func, const T _param_def) :
      |   ^~~~~~~
a.cc:28:3: note:   candidate expects 2 arguments, 3 provided
a.cc:7:7: note: candidate: 'Segtree<int>::Segtree(const Segtree<int>&)'
    7 | class Segtree{
      |       ^~~~~~~
a.cc:7:7: note:   candidate expects 1 argument, 3 provided
a.cc:7:7: note: candidate: 'Segtree<int>::Segtree(Segtree<int>&&)'
a.cc:7:7: note:   candidate expects 1 argument, 3 provided
a.cc: In instantiation of 'T Segtree<T>::segtree_query_partial(int, int, int, int, int) [with T = int]':
a.cc:48:12:   required from 'T Segtree<T>::query(int, int) [with T = int]'
   48 |     return segtree_query_partial(a, b, 0, 0, nbin);
      |            ^~~~~~~~~~~~~~~~~~~~~
a.cc:62:36:   required from here
   62 |     std::cout << std::max(seg.query(0, i), seg.query(i+1, N)) << "\n";
      |                           ~~~~~~~~~^~~~~~
a.cc:17:20: error: 'seg_func' was not declared in this scope
   17 |     return seg_func(v_l, v_r);
      |            ~~~~~~~~^~~~~~~~~~