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

#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(), (x).end()
#define C(x) cout << #x << " : " << x << endl
#define scanf scanf_s

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;
template <typename Monoid, typename Operand> class SegTree {
public:
  Monoid *tree;
  size_t size;
  int32 i;
  //?????????????????????
  SegTree(size_t length) {
    --length;
    size = length;
    if (size & 0xffff0000) {
      size = size & 0xffff0000;
    }
    if (size & 0xff00ff00) {
      size = size & 0xff00ff00;
    }
    if (size & 0xf0f0f0f0) {
      size = size & 0xf0f0f0f0;
    }
    if (size & 0xcccccccc) {
      size = size & 0xcccccccc;
    }
    if (size & 0xaaaaaaaa) {
      size = size & 0xaaaaaaaa;
    }
    if (length) {
      size <<= 1;
    } else {
      size = 1;
    }
    tree = (Monoid *)calloc(size << 1, sizeof(Monoid));
  }
  //?????????
  void set(bool merge) {
    i = size << 1;
    while (--i) {
      tree[i].set();
    }
    if (merge) {
      i = size;
      while (--i) {
        tree[i] = tree[i << 1] + tree[i << 1 | 1];
      }
    }
  }
  // tree[index]???data??§??´??°
  void update(size_t index, Operand &data) {
    index += size;
    tree[index] = tree[index] * data;
    while (index >>= 1)
      tree[index] = tree[index << 1] + tree[index << 1 | 1];
  }
  //[begin,end)??????????????????
  Monoid range(size_t begin, size_t end) {
    Monoid retL, retR;
    for (begin += size, end += size; begin < end; begin >>= 1, end >>= 1) {
      if (begin & 1)
        retL = retL + tree[begin++];
      if (end & 1)
        retR = tree[end - 1] + retR;
    }
    return retL + retR;
  }
};
struct SUB {
  int32 e;
  SUB() { set(); }
  SUB(int32 x) { e = x; }
  void set() { e = 1000000000; }
  SUB operator*(const SUB &other) { return other; }
};
struct MIN {
  int32 e;
  MIN() { set(); }
  MIN(int32 x) { e = x; }
  void set() { e = 2147483647; }
  MIN operator+(const MIN &other) {
    return e < other.e ? MIN(e) : MIN(other.e);
  };
  MIN operator*(const SUB &other) { return MIN(other.e); }
};

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  size_t n, q;
  cin >> n >> q;
  bool c;
  size_t x, y;
  SUB z;
  SegTree<MIN, SUB> t(n);
  t.set(0);
  while (q--) {
    cin >> c;
    if (c) {
      cin >> x >> y;
      printf("%d\\n", t.range(x, y + 1).e);
    } else {
      cin >> x >> z.e;
      t.update(x, z);
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(), (x).end()
#define C(x) cout << #x << " : " << x << endl
#define scanf scanf_s

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;
template <typename Monoid, typename Operand> class SegTree {
public:
  Monoid *tree;
  size_t size;
  int32 i;
  //?????????????????????
  SegTree(size_t length) {
    --length;
    if (length & 0xffff0000) {
      size = length & 0xffff0000;
    }
    if (size & 0xff00ff00) {
      size = size & 0xff00ff00;
    }
    if (size & 0xf0f0f0f0) {
      size = size & 0xf0f0f0f0;
    }
    if (size & 0xcccccccc) {
      size = size & 0xcccccccc;
    }
    if (size & 0xaaaaaaaa) {
      size = size & 0xaaaaaaaa;
    }
    if (length) {
      size <<= 1;
    } else {
      size = 1;
    }
    tree = (Monoid *)calloc(size << 1, sizeof(Monoid));
  }
  //?????????
  void set(bool merge) {
    i = size << 1;
    while (--i) {
      tree[i].set();
    }
    if (merge) {
      i = size;
      while (--i) {
        tree[i] = tree[i << 1] + tree[i << 1 | 1];
      }
    }
  }
  // tree[index]???data??§??´??°
  void update(size_t index, Operand &data) {
    index += size;
    tree[index] = tree[index] * data;
    while (index >>= 1)
      tree[index] = tree[index << 1] + tree[index << 1 | 1];
  }
  //[begin,end)??????????????????
  Monoid range(size_t begin, size_t end) {
    Monoid retL, retR;
    for (begin += size, end += size; begin < end; begin >>= 1, end >>= 1) {
      if (begin & 1)
        retL = retL + tree[begin++];
      if (end & 1)
        retR = tree[end - 1] + retR;
    }
    return retL + retR;
  }
};
struct SUB {
  int32 e;
  SUB() { set(); }
  SUB(int32 x) { e = x; }
  void set() { e = 1000000000; }
  SUB operator*(const SUB &other) { return other; }
};
struct MIN {
  int32 e;
  MIN() { set(); }
  MIN(int32 x) { e = x; }
  void set() { e = 2147483647; }
  MIN operator+(const MIN &other) {
    return e < other.e ? MIN(e) : MIN(other.e);
  };
  MIN operator*(const SUB &other) { return MIN(other.e); }
};

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  size_t n, q;
  cin >> n >> q;
  bool c;
  size_t x, y;
  SUB z;
  SegTree<MIN, SUB> t(n);
  t.set(0);
  while (q--) {
    cin >> c;
    if (c) {
      cin >> x >> y;
      printf("%d\\n", t.range(x, y + 1).e);
    } else {
      cin >> x >> z.e;
      t.update(x, z);
    }
  }
  return 0;
}