Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

#define rep(i, j) for (int i = 0; i < (int)(j); i++)
#define repeat(i, j, k) for (int i = (j); i < (int)(k); i++)
#define rrep(i, j) for (int i = (j); i >= 0; i--)
#define all(v) v.begin(), v.end()

template <class T, T f(T, T), T unit> class SegmentTree {
public:
  int n;
  vector<T> data;
  // function<T(T, T) > f; // ?????????
  // T unit;               // f ?????????????????????
  SegmentTree(int nn) {
    n = 1;
    while (n < nn)
      n *= 2;
    data.resize(2 * n - 1, unit);
  }
  // index k in [0, n) ????????? val ?????´??°
  void update(int k, T val) {
    assert(0 <= k and k < n);
    k += n - 1;
    data[k] = val;
    while (k > 0) {
      k = parent(k);
      data[k] = f(data[left_child(k)], data[right_child(k)]);
    }
  }
  // [a, b)
  int query(int a, int b) {
    assert(0 <= a and a < b and b <= n);
    return query(a, b, 0, 0, n);
  }

private:
  //[a, b) ????????¨???, now???????????´???, [l,r)?????????????????´???
  T query(int a, int b, int now, int l, int r) {
    if (out_of_range(a, b, l, r))
      return unit;
    if (within_range(a, b, l, r))
      return data[now];
    else { // cross range
      T vleft = query(a, b, left_child(now), l, (l + r) / 2);
      T vright = query(a, b, right_child(now), (l + r) / 2, r);
      return f(vleft, vright);
    }
  }
  bool out_of_range(int a, int b, int l, int r) { return r <= a or b <= l; }
  bool within_range(int a, int b, int l, int r) { return a <= l and r <= b; }
  int left_child(int i) { return i * 2 + 1; }
  int right_child(int i) { return i * 2 + 2; }
  int parent(int i) { return (i - 1) / 2; }
};

// -----------------------------------------------------------------------

template <class T> T rmq_op(T a, T b) { return min(a, b); }

template <class T, T INF>
using RangeMinimumQuery = SegmentTree<T, rmq_op<T>, INF>;

/*
template<class T>
class RangeMinimumQuery : public SegmentTree<T> {
  public:
    RangeMinimumQuery(int n) : SegmentTree<T>(n, [](T a, T b){ min(a, b); },
INF) {}
};

template<class T>
class RangeMaximumQuery : public SegmentTree<T> {
  public:
    RangeMaximumQuery(int n) : SegmentTree<T>(n, [](T a, T b){ max(a, b); },
-INF) {}
};

template<class T>
class RangeSumQuery : public SegmentTree<T> {
  public:
    RangeSumQuery(int n) : SegmentTree<T>(n, [](T a, T b){ a + b; }, 0) {}
};

*/

int main() {
  int n, q;
  cin >> n >> q;
  RangeMinimumQuery<long long, (1LL << 31) - 1> rmq(n);
  rep(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0)
      rmq.update(x, y);
    else
      cout << rmq.query(x, y + 1) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define rep(i, j) for (int i = 0; i < (int)(j); i++)
#define repeat(i, j, k) for (int i = (j); i < (int)(k); i++)
#define rrep(i, j) for (int i = (j); i >= 0; i--)
#define all(v) v.begin(), v.end()
constexpr int INF = 1 << 30;

#include <functional>

template <class T, T f(T, T), T unit> class SegmentTree {
public:
  int n;
  vector<T> data;
  // function<T(T, T) > f; // ?????????
  // T unit;               // f ?????????????????????
  SegmentTree(int nn) {
    n = 1;
    while (n < nn)
      n *= 2;
    data.resize(2 * n - 1, unit);
  }
  // index k in [0, n) ????????? val ?????´??°
  void update(int k, T val) {
    assert(0 <= k and k < n);
    k += n - 1;
    data[k] = val;
    while (k > 0) {
      k = parent(k);
      data[k] = f(data[left_child(k)], data[right_child(k)]);
    }
  }
  // [a, b)
  int query(int a, int b) {
    assert(0 <= a and a < b and b <= n);
    return query(a, b, 0, 0, n);
  }

private:
  //[a, b) ????????¨???, now???????????´???, [l,r)?????????????????´???
  T query(int a, int b, int now, int l, int r) {
    if (out_of_range(a, b, l, r))
      return unit;
    if (within_range(a, b, l, r))
      return data[now];
    else { // cross range
      T vleft = query(a, b, left_child(now), l, (l + r) / 2);
      T vright = query(a, b, right_child(now), (l + r) / 2, r);
      return f(vleft, vright);
    }
  }
  bool out_of_range(int a, int b, int l, int r) { return r <= a or b <= l; }
  bool within_range(int a, int b, int l, int r) { return a <= l and r <= b; }
  int left_child(int i) { return i * 2 + 1; }
  int right_child(int i) { return i * 2 + 2; }
  int parent(int i) { return (i - 1) / 2; }
};

// -----------------------------------------------------------------------

template <class T> T rmq_op(T a, T b) { return min(a, b); }

template <class T> using RangeMinimumQuery = SegmentTree<T, rmq_op<T>, INF>;

int main() {
  int n, q;
  cin >> n >> q;
  RangeMinimumQuery<int> rmq(n);
  rep(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0)
      rmq.update(x, y);
    else
      cout << rmq.query(x, y) << endl;
  }
  return 0;
}