Problem p02345 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i, a, b) for (long i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (long i = (a); i >= (b); --i)

#define REP(i, a) FOR(i, 0, a)
#define RREP(i, a) RFOR(i, a, 0)

#define EACH(i, a) for (auto(i) = (a).begin(), _END = (a).end(); i != _END; ++i)
#define REACH(i, a)                                                            \
  for (auto(i) = (a).rbegin(), _END = (a).rend(); i != _END; ++i)

// Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a, x) ((a).find(x) != (a).end())
#define SORT(a) sort(ALL(a))

// Setting
#define OPT                                                                    \
  std::cin.tie(0);                                                             \
  std::ios::sync_with_stdio(false);

// debug message
bool debug = true;
#define MSG(s)                                                                 \
  if (debug) {                                                                 \
    std::cout << s << std::endl;                                               \
  }
#define DEBUG(x)                                                               \
  if (debug) {                                                                 \
    std::cout << "debug(" << #x << "): " << x << std::endl;                    \
  }

// alias
typedef long long LL;
typedef std::vector<int> VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::pair<int, int> PII;

template <class T> struct RMQ {
  T sz;
  T sq;

  std::vector<T> data;
  std::vector<T> bucket;
  RMQ(T size) {
    sq = std::ceil(std::sqrt(size));
    sz = size;
    data.resize(size, -1);
    bucket.resize(sq, -1);
  }
  RMQ(T size, T init) : data(size, init) {
    sq = std::ceil(std::sqrt(size));
    sz = size;
    data.resize(size, init);
    bucket.resize(sq, init);
  }
  void update(T i, T x) {
    data[i] = x;
    T minVal = data[i];
    T k = i / sq;
    FOR(j, k * sq, (k + 1) * sq) { minVal = std::min(minVal, data[j]); }
    bucket[k] = minVal;
  }
  T find(T s, T t) {
    if (s == t)
      return data[s];
    T val = (1LL << 31) - 1;
    REP(i, sq) {
      T l = i * sq, r = (i + 1) * sq;
      if (r <= s || t <= l) {
        continue;
      }

      if (s <= l && r <= t) {
        val = std::min(val, bucket[i]);
      } else {
        FOR(j, std::max(s, l), std::min(t, r) + 1) {
          val = std::min(val, data[j]);
        }
      }
    }
    return val;
  }
};

int main() {
  int n, q, c, x, y;
  std::cin >> n >> q;
  RMQ<long> rmq = RMQ<long>(std::pow(n, 2), (1LL << 31) - 1);
  REP(i, q) {
    std::cin >> c >> x >> y;
    if (c == 0) {
      rmq.update(x, y);
    } else {
      std::cout << rmq.find(x, y) << std::endl;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i, a, b) for (long i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (long i = (a); i >= (b); --i)

#define REP(i, a) FOR(i, 0, a)
#define RREP(i, a) RFOR(i, a, 0)

#define EACH(i, a) for (auto(i) = (a).begin(), _END = (a).end(); i != _END; ++i)
#define REACH(i, a)                                                            \
  for (auto(i) = (a).rbegin(), _END = (a).rend(); i != _END; ++i)

// Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a, x) ((a).find(x) != (a).end())
#define SORT(a) sort(ALL(a))

// Setting
#define OPT                                                                    \
  std::cin.tie(0);                                                             \
  std::ios::sync_with_stdio(false);

// debug message
bool debug = true;
#define MSG(s)                                                                 \
  if (debug) {                                                                 \
    std::cout << s << std::endl;                                               \
  }
#define DEBUG(x)                                                               \
  if (debug) {                                                                 \
    std::cout << "debug(" << #x << "): " << x << std::endl;                    \
  }

// alias
typedef long long LL;
typedef std::vector<int> VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::pair<int, int> PII;

template <class T> struct RMQ {
  T sz;
  T sq;

  std::vector<T> data;
  std::vector<T> bucket;
  RMQ(T size) {
    sq = std::ceil(std::sqrt(size));
    sz = size;
    data.resize(size, -1);
    bucket.resize(sq, -1);
  }
  RMQ(T size, T init) : data(size, init) {
    sq = std::ceil(std::sqrt(size));
    sz = size;
    data.resize(size, init);
    bucket.resize(sq, init);
  }
  void update(T i, T x) {
    data[i] = x;
    T minVal = data[i];
    T k = i / sq;
    FOR(j, k * sq, (k + 1) * sq) { minVal = std::min(minVal, data[j]); }
    bucket[k] = minVal;
  }
  T find(T s, T t) {
    if (s == t)
      return data[s];
    T val = (1LL << 31) - 1;
    REP(i, sq) {
      T l = i * sq, r = (i + 1) * sq;
      if (r <= s || t <= l) {
        continue;
      }

      if (s <= l && r <= t) {
        val = std::min(val, bucket[i]);
      } else {
        FOR(j, std::max(s, l), std::min(t, r) + 1) {
          val = std::min(val, data[j]);
        }
      }
    }
    return val;
  }
};

int main() {
  int n, q, c, x, y;
  std::cin >> n >> q;
  RMQ<long> rmq = RMQ<long>(100000, (1LL << 31) - 1);
  REP(i, q) {
    std::cin >> c >> x >> y;
    if (c == 0) {
      rmq.update(x, y);
    } else {
      std::cout << rmq.find(x, y) << std::endl;
    }
  }
}