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

#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template <class T> ostream &operator<<(ostream &os, vector<T> const &);
template <int n, class... T>
typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,
                                                  tuple<T...> const &) {}
template <int n, class... T>
typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os,
                                                 tuple<T...> const &t) {
  os << (n == 0 ? "" : " ") << get<n>(t);
  _ot<n + 1>(os, t);
}
template <class... T> ostream &operator<<(ostream &os, tuple<T...> const &t) {
  _ot<0>(os, t);
  return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
  return os << "(" << p.first << ", " << p.second << ") ";
}
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
#ifdef DEBUG
#define dump(...)                                                              \\
  (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) << " [" << __LINE__ << "]" \\
        << endl)
#else
#define dump(...)
#endif

int const inf = (1LL << 31) - 1;
int const B = 1024;
struct RMQ {
  int n;
  vector<int> Bmin;
  vector<vector<int>> dat;
  RMQ(int n_) {
    n = n_;
    if (n % B)
      n += B - n % B;
    dat.assign(n / B, vector<int>(B, inf));
    Bmin.assign(n / B, inf);
  }
  void set(int idx, int x) {
    get(idx) = x;
    Bmin[idx / B] = inf;
    for (int i = 0; i < B; i++)
      Bmin[idx / B] = min(Bmin[idx / B], get(idx / B * B + i));
  }
  int &get(int idx) { return dat[idx / B][idx % B]; }
  int rmq(int l, int r) {
    int res = inf;
    if (l / B != r / B) {
      while (l % B) {
        res = min(res, get(l));
        l++;
      }
      while (r % B) {
        r--;
        res = min(res, get(r));
      }
      while (l < r) {
        res = min(res, Bmin[l / B]);
        l += B;
      }
    } else {
      while (l < r) {
        res = min(res, get(l));
        l++;
      }
    }
    return res;
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  RMQ rmq(n);
  rep(i, q) {
    int c, x, y;
    cin >> c >> x >> y;
    if (c)
      cout << rmq.rmq(x, y + 1) << endl;
    else
      rmq.set(x, y);
  }
}

Error: 0

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template <class T> ostream &operator<<(ostream &os, vector<T> const &);
template <int n, class... T>
typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,
                                                  tuple<T...> const &) {}
template <int n, class... T>
typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os,
                                                 tuple<T...> const &t) {
  os << (n == 0 ? "" : " ") << get<n>(t);
  _ot<n + 1>(os, t);
}
template <class... T> ostream &operator<<(ostream &os, tuple<T...> const &t) {
  _ot<0>(os, t);
  return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
  return os << "(" << p.first << ", " << p.second << ") ";
}
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
#ifdef DEBUG
#define dump(...)                                                              \\
  (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) << " [" << __LINE__ << "]" \\
        << endl)
#else
#define dump(...)
#endif

int const inf = (1LL << 31) - 1;
int const B = 1024;
struct RMQ {
  int n;
  vector<int> Bmin;
  vector<vector<int>> dat;
  RMQ(int n_) {
    n = n_;
    if (n % B)
      n += B - n % B;
    dat.assign(n / B, vector<int>(B, inf));
    Bmin.assign(n / B, inf);
  }
  void set(int idx, int x) {
    get(idx) = x;
    Bmin[idx / B] = inf;
    for (int i = 0; i < B; i++)
      Bmin[idx / B] = min(Bmin[idx / B], get(idx / B * B + i));
  }
  int &get(int idx) { return dat[idx / B][idx % B]; }
  int rmq(int l, int r) {
    int res = inf;
    if (l / B != r / B) {
      while (l % B) {
        res = min(res, get(l));
        l++;
      }
      while (r % B) {
        r--;
        res = min(res, get(--r));
      }
      while (l < r) {
        res = min(res, Bmin[l / B]);
        l += B;
      }
    } else {
      while (l < r) {
        res = min(res, get(l));
        l++;
      }
    }
    return res;
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  RMQ rmq(n);
  rep(i, q) {
    int c, x, y;
    cin >> c >> x >> y;
    if (c)
      cout << rmq.rmq(x, y + 1) << endl;
    else
      rmq.set(x, y);
  }
}