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

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for (int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct {
  int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = INT_MAX;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

template <typename T> struct RMQ {
private:
  ll N = 1;
  vector<T> node;

public:
  RMQ(vector<T> vec) {
    ll size = vec.size();

    while (N < size) {
      N *= 2;
    }

    node.resize(2 * N - 1, iINF);

    REP(i, size) { node[i + N - 1] = vec[i]; }

    for (int i = N - 2; 0 <= i; i--) {
      node[i] = min(node[2 * i + 1], node[2 * i + 2]);
    }
  }

  void update(int i, T value) {
    i += (N - 1);

    node[i] = value;

    while (i > 0) {
      i = (i - 1) / 2;

      node[i] = min(node[2 * i + 1], node[2 * i + 2]);
    }
  }

  T getMin(int a, int b, int i = 0, int l = 0, int r = -1) {
    if (r < 0) {
      r = N;
    }

    if (r <= a || b <= l) {
      return iINF;
    }

    if (a <= l && r <= b) {
      return node[i];
    }

    T vl = getMin(a, b, 2 * i + 1, l, (l + r) / 2);

    T vr = getMin(a, b, 2 * i + 2, (l + r) / 2, r);

    return min(vl, vr);
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N, Q;
  cin >> N >> Q;

  RMQ<ll> rmq(vector<ll>(N, iINF));

  REP(i, Q) {
    int com, x, y;
    cin >> com >> x >> y;

    if (com == 0) {
      rmq.update(x, y);
    } else {
      cout << rmq.getMin(x, y + 1) << endl;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for (int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct {
  int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = INT_MAX;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

template <typename T> struct RMQ {
private:
  int N = 1;
  vector<T> node;

public:
  RMQ(vector<T> vec) {
    int size = vec.size();

    while (N < size) {
      N *= 2;
    }

    node.resize(2 * N - 1, iINF);

    REP(i, N) { node[i + N - 1] = vec[i]; }

    for (int i = N - 2; 0 <= i; i--) {
      node[i] = min(node[2 * i + 1], node[2 * i + 2]);
    }
  }

  void update(int i, T value) {
    i += (N - 1);

    node[i] = value;

    while (i > 0) {
      i = (i - 1) / 2;

      node[i] = min(node[2 * i + 1], node[2 * i + 2]);
    }
  }

  T getMin(int a, int b, int i = 0, int l = 0, int r = -1) {
    if (r < 0) {
      r = N;
    }

    if (r <= a || b <= l) {
      return iINF;
    }

    if (a <= l && r <= b) {
      return node[i];
    }

    T vl = getMin(a, b, 2 * i + 1, l, (l + r) / 2);

    T vr = getMin(a, b, 2 * i + 2, (l + r) / 2, r);

    return min(vl, vr);
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, Q;
  cin >> N >> Q;

  RMQ<ll> rmq(vector<ll>(N, iINF));

  REP(i, Q) {
    int com, x, y;
    cin >> com >> x >> y;

    if (com == 0) {
      rmq.update(x, y);
    } else {
      cout << rmq.getMin(x, y + 1) << endl;
    }
  }

  return 0;
}