Language: C++

#include <iostream>

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:7:18: error: 'function' does not name a type; did you mean 'union'?
    7 |   using func_t = function<T(T, T)>;
      |                  ^~~~~~~~
      |                  union
a.cc:10:3: error: 'func_t' does not name a type
   10 |   func_t merge;
      |   ^~~~~~
a.cc:11:3: error: 'vector' does not name a type
   11 |   vector<T> data;
      |   ^~~~~~
a.cc:23:28: error: 'func_t' has not been declared
   23 |   SegmentTree(int n, T id, func_t merge) :
      |                            ^~~~~~
a.cc: In member function 'T SegmentTree<T>::sub(int, int, int, int, int)':
a.cc:14:40: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   14 |     if (l <= lb && ub <= r) return data[node];
      |                                        ^
a.cc: In constructor 'SegmentTree<T>::SegmentTree(int, T, int)':
a.cc:24:25: error: class 'SegmentTree<T>' does not have any field named 'merge'
   24 |     n(size(n)), id(id), merge(merge), data(n * 2, id) {}
      |                         ^~~~~
a.cc:24:39: error: class 'SegmentTree<T>' does not have any field named 'data'
   24 |     n(size(n)), id(id), merge(merge), data(n * 2, id) {}
      |                                       ^~~~
a.cc: In member function 'void SegmentTree<T>::add(int, T)':
a.cc:26:5: error: there are no arguments to 'assert' that depend on a template parameter, so a declaration of 'assert' must be available [-fpermissive]
   26 |     assert (0 <= p && p < n);
      |     ^~~~~~
a.cc:26:5: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc:28:9: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   28 |     data[p] += val;
      |         ^
a.cc:31:11: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   31 |       data[p] = merge(data[l], data[r]);
      |           ^
a.cc:31:27: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   31 |       data[p] = merge(data[l], data[r]);
      |                           ^
a.cc:31:36: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   31 |       data[p] = merge(data[l], data[r]);
      |                                    ^
a.cc:31:17: error: there are no arguments to 'merge' that depend on a template parameter, so a declaration of 'merge' must be available [-fpermissive]
   31 |       data[p] = merge(data[l], data[r]);
      |                 ^~~~~
a.cc: In function 'int main()':
a.cc:42:30: error: invalid user-defined conversion from 'main()::<lambda(int, int)>' to 'int' [-fpermissive]
   42 |   SegmentTree<int> seg(n, 0, [](int a, int b){return min(a, b);});
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:42:30: note: candidate is: 'constexpr main()::<lambda(int, int)>::operator int (*)(int, int)() const' (near match)
   42 |   SegmentTree<int> seg(n, 0, [](int a, int b){return min(a, b);});
      |                              ^
a.cc:42:30: note:   no known conversion from 'int (*)(int, int)' to 'int'
a.cc:23:35: note:   initializing argument 3 of 'SegmentTree<T>::SegmentTree(int, T, int) [with T = int]'
   23 |   SegmentTree(int n, T id, func_t merge) :
      |                            ~~~~~~~^~~~~
a.cc: In instantiation of 'void SegmentTree<T>::add(int, T) [with T = int]':
a.cc:46:17:   required from here
   46 |     else seg.add(x, y);
      |          ~~~~~~~^~~~~~
a.cc:26:12: error: 'assert' was not declared in this scope
   26 |     assert (0 <= p && p < n);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:2:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    1 | #include <iostream>
  +++ |+#include <cassert>
    2 | 
a.cc: In instantiation of 'T SegmentTree<T>::sub(int, int, int, int, int) [with T = int]':
a.cc:35:12:   required from 'T SegmentTree<T>::getSum(int, int) [with T = int]'
   35 |     return sub(l, r, 1, 0, n);
      |            ^~~
a.cc:45:32:   required from here
   45 |     if (com) cout << seg.getSum(x, y+1) << endl;
      |                      ~~~~~~~~~~^~~~~~~~
a.cc:17:17: error: 'merge' was not declared in this scope
   17 |     return merge(vl, vr);
      |            ~~~~~^~~~~~~~