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

#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>

#define NUM 2147483647

using namespace std;

struct Info {
  int left, right, minimum;
};

Info *info;
int *index_table;
int N;

void func(int index) {
  int div = info[index].right - info[index].left;

  if (div != 0) {
    if (div % 2 == 1) { //????????????2?????????????????´???
      info[index * 2 + 1].left = info[index].left;
      info[index * 2 + 1].right = (info[index].left + info[index].right) / 2;
      func(index * 2 + 1);
      info[index * 2 + 2].left = (info[index].left + info[index].right) / 2 + 1;
      info[index * 2 + 2].right = info[index].right;
      func(index * 2 + 2);
    } else {
      info[index * 2 + 1].left = info[index].left;
      info[index * 2 + 1].right = (info[index].left + info[index].right) / 2;
      func(index * 2 + 1);
      info[index * 2 + 2].left = (info[index].left + info[index].right) / 2 + 1;
      info[index * 2 + 2].right = info[index].right;
      func(index * 2 + 2);
    }
  } else {
    index_table[info[index].left] = index;
  }
}

void update(int index, int new_value) {
  info[index_table[index]].minimum = new_value;

  if (index_table[index] == 0)
    return;
  int t = (index_table[index] - 1) / 2;

  while (true) {
    info[t].minimum = min(info[2 * t + 1].minimum, info[2 * t + 2].minimum);
    if (t == 0)
      break;
    t = (t - 1) / 2;
  }
}

int getMinimum(int index, int left, int right) {
  if (info[index].left > right || info[index].right < left) {
    return NUM;
  } else if (info[index].left >= left && info[index].right <= right) {
    return info[index].minimum;
  } else {
    return min(getMinimum(index * 2 + 1, left, right),
               getMinimum(index * 2 + 2, left, right));
  }
}

int main() {

  int Q, type, a, b;
  scanf("%d %d", &N, &Q);

  info = (Info *)malloc(sizeof(Info) * (4 * N));
  for (int i = 0; i < 4 * N; i++) {
    info[i].minimum = NUM;
    info[i].left = info[i].right = -1;
  }
  index_table = new int[N];

  info[0].left = 0, info[0].right = N - 1;

  func(0);

  for (int loop = 0; loop < Q; loop++) {
    scanf("%d %d %d", &type, &a, &b);
    if (type == 0) {
      update(a, b);
    } else {
      printf("%d\\n", getMinimum(0, a, b));
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>

#define NUM 2147483647

using namespace std;

struct Info {
  int left, right, minimum, left_child, right_child;
};

Info *info;
int *index_table;

void func(int index) {
  int div = info[index].right - info[index].left;

  if (div != 0) {
    info[index].left_child = index * 2 + 1;
    info[index].right_child = index * 2 + 2;

    if (div % 2 == 1) { //????????????2?????????????????´???
      info[index * 2 + 1].left = info[index].left;
      info[index * 2 + 1].right = (info[index].left + info[index].right) / 2;
      func(index * 2 + 1);
      info[index * 2 + 2].left = (info[index].left + info[index].right) / 2 + 1;
      info[index * 2 + 2].right = info[index].right;
      func(index * 2 + 2);
    } else {
      info[index * 2 + 1].left = info[index].left;
      info[index * 2 + 1].right = (info[index].left + info[index].right) / 2;
      func(index * 2 + 1);
      info[index * 2 + 2].left = (info[index].left + info[index].right) / 2 + 1;
      info[index * 2 + 2].right = info[index].right;
      func(index * 2 + 2);
    }
  } else {
    index_table[info[index].left] = index;
  }
}

void update(int index, int new_value) {
  info[index_table[index]].minimum = new_value;

  if (index_table[index] == 0)
    return;
  int t = (index_table[index] - 1) / 2;

  while (true) {
    info[t].minimum = min(info[2 * t + 1].minimum, info[2 * t + 2].minimum);
    if (t == 0)
      break;
    t = (t - 1) / 2;
  }
}

int getMinimum(int index, int left, int right) {
  if (info[index].left > right || info[index].right < left) {
    return NUM;
  } else if (info[index].left >= left && info[index].right <= right) {
    return info[index].minimum;
  } else {
    return min(getMinimum(info[index].left_child, left, right),
               getMinimum(info[index].right_child, left, right));
  }
}

int main() {

  int N, Q, type, a, b;
  scanf("%d %d", &N, &Q);

  info = (Info *)malloc(sizeof(Info) * (3 * N));
  for (int i = 0; i < 3 * N; i++) {
    info[i].minimum = NUM;
    info[i].left = info[i].right = -1;
  }
  index_table = new int[N];

  info[0].left = 0, info[0].right = N - 1;

  func(0);

  for (int loop = 0; loop < Q; loop++) {
    scanf("%d %d %d", &type, &a, &b);
    if (type == 0) {
      update(a, b);
    } else {
      printf("%d\\n", getMinimum(0, a, b));
    }
  }
  return 0;
}