Language: C++

#include <vector>
#include <iostream>
#include <cassert>
#include <algorithm>

using namespace std;

template <typename T>
class SegmentTree {
  using func_t = function<T(T, T)>;
  const int n;
  const T id;
  func_t merge;
  vector<T> data;
  T sub(int l, int r, int node, int lb, int ub) {
    if (ub <= l || r <= lb) return id;
    if (l <= lb && ub <= r) return data[node];
    T vl = sub(l, r, node * 2 + 0, lb, (lb + ub) / 2);
    T vr = sub(l, r, node * 2 + 1, (lb + ub) / 2, ub);
    return merge(vl, vr);
  }
  int size(int n) {
    return n == 1 ? n : size((n + 1) / 2) * 2;
  }
public:
  SegmentTree(int n, T id, func_t merge) :
    n(size(n)), id(id), merge(merge), data(n * 2, id) {}
  void add(int p, T val) {
    assert (0 <= p && p < n);
    p += n;
    data[p] += val;
    while (p /= 2) {
      int l = p * 2, r = p * 2 + 1;
      data[p] = merge(data[l], data[r]);
    }
  }
  T getSum(int l, int r) {
    return sub(l, r, 1, 0, n);
  }
};

int main() {
  int n, q, com, x, y;
  cin >> n >> q;
  SegmentTree<int> seg(n, 0, [](int a, int b){return min(a, b);});
  while (q--) {
    cin >> com >> x >> y;
    if (com) cout << seg.getSum(x, y+1) << endl;
    else seg.add(x, y);
  }
  return 0;
}

Compiler output:
a.cc:10:18: error: 'function' does not name a type; did you mean 'union'?
   10 |   using func_t = function<T(T, T)>;
      |                  ^~~~~~~~
      |                  union
a.cc:13:3: error: 'func_t' does not name a type
   13 |   func_t merge;
      |   ^~~~~~
a.cc:26:28: error: 'func_t' has not been declared
   26 |   SegmentTree(int n, T id, func_t merge) :
      |                            ^~~~~~
a.cc: In constructor 'SegmentTree<T>::SegmentTree(int, T, int)':
a.cc:27:25: error: class 'SegmentTree<T>' does not have any field named 'merge'
   27 |     n(size(n)), id(id), merge(merge), data(n * 2, id) {}
      |                         ^~~~~
a.cc: In function 'int main()':
a.cc:45:30: error: invalid user-defined conversion from 'main()::<lambda(int, int)>' to 'int' [-fpermissive]
   45 |   SegmentTree<int> seg(n, 0, [](int a, int b){return min(a, b);});
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:45:30: note: candidate is: 'constexpr main()::<lambda(int, int)>::operator int (*)(int, int)() const' (near match)
   45 |   SegmentTree<int> seg(n, 0, [](int a, int b){return min(a, b);});
      |                              ^
a.cc:45:30: note:   no known conversion from 'int (*)(int, int)' to 'int'
a.cc:26:35: note:   initializing argument 3 of 'SegmentTree<T>::SegmentTree(int, T, int) [with T = int]'
   26 |   SegmentTree(int n, T id, func_t merge) :
      |                            ~~~~~~~^~~~~
a.cc: In instantiation of 'void SegmentTree<T>::add(int, T) [with T = int]':
a.cc:49:17:   required from here
   49 |     else seg.add(x, y);
      |          ~~~~~~~^~~~~~
a.cc:34:22: error: no matching function for call to 'merge(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   34 |       data[p] = merge(data[l], data[r]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:4857:5: note: candidate: 'template<class _IIter1, class _IIter2, class _OIter> _OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter)'
 4857 |     merge(_InputIterator1 __first1, _InputIterator1 __last1,
      |     ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4857:5: note:   candidate expects 5 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:4908:5: note: candidate: 'template<class _IIter1, class _IIter2, class _OIter, class _Compare> _OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare)'
 4908 |     merge(_InputIterator1 __first1, _InputIterator1 __last1,
      |     ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4908:5: note:   candidate expects 6 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:412:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::merge(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _ForwardIterator, _Compare)'
  412 | merge(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
      | ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:412:1: note:   candidate expects 7 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:417:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::merge(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _ForwardIterator)'
  417 | merge(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
      | ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:417:1: note:   candidate expects 6 arguments, 2 provided
a.cc: In instantiation of 'T SegmentTree<T>::sub(int, int, int, int, int) [with T = int]':
a.cc:38:12:   required from 'T SegmentTree<T>::getSum(int, int) [with T = int]'
   38 |     return sub(l, r, 1, 0, n);
      |            ^~~
a.cc:48:32:   required from here
   48 |     if (com) cout << seg.getSum(x, y+1) << endl;
      |                      ~~~~~~~~~~^~~~~~~~
a.cc:20:17: error: no matching function for call to 'merge(int&, int&)'
   20 |     return merge(vl, vr);
      |            ~~~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4857:5: note: candidate: 'template<class _IIter1, class _IIter2, class _OIter> _OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter)'
 4857 |     merge(_InputIterator1 __first1, _InputIterator1 __last1,
      |     ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4857:5: note:   candidate expects 5 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:4908:5: note: candidate: 'template<class _IIter1, class _IIter2, class _OIter, class _Compare> _OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare)'
 4908 |     merge(_InputIterator1 __first1, _InputIterator1 __last1,
      |     ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4908:5: note:   candidate expects 6 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:412:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::merge(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _ForwardIterator, _Compare)'
  412 | merge(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
      | ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:412:1: note:   candidate expects 7 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:417:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::merge(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _ForwardIterator)'
  417 | merge(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
      | ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:417:1: note:   candidate expects 6 arguments, 2 provided