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

/*
        DSL: domain-specific language
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_F
        12/5/2017
        TLE: 15/22, doing the query(use loop for (i,j))
        solution: add another ele in node to keep element, look liks add more
   element is hard to update the Final solution1.0: use the recusive and
*/

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
// #define N 131072 //100000 why
#define MAXVAL ((long int)((unsigned long)(1 << 31) - 1)) //*2

int min(int a, int b) { return a > b ? b : a; }
int query(int search_left, int search_right, int node_id, int node_left,
          int node_right);
void update(int update_left, int update_right, int new_value, int node_id,
            int node_left, int node_right);
int data[2 * 131072 + 100]; // the size of array, for present the tree
// BEGIN FROM 0;
int main() {
  int n = 0, q = 0;
  int N = 1;
  int a, b, c;
  // read from the file
  FILE *fp;
  // fp = fopen("in.txt","r");
  scanf("%d %d", &n, &q);

  // how to calculate the beginning index (the last layer of the tree)
  // how many nodes in last layer
  while (N < n)
    N = N << 1;
  // printf("N%d\\n",N);
  for (int i = 0; i <= 2 * N - 2; i++) {
    data[i] = MAXVAL;
  }

  // printf("count:%d",count);

  for (int i = 1; i <= q; i++) {
    int temp = 0;
    scanf("%d", &temp);
    if (temp == 0) {
      scanf("%d %d %d", &a, &b, &c);
      update(a, b, c, 0, 0, N - 1);
    } else if (temp == 1) {
      scanf("%d %d", &a, &b);
      printf("%d\\n", query(a, b, 0, 0, N - 1));
    }
  }
  return 0;
}
/*
        update the value in the array, no return
        foramtion: if() return;
                                f();
*/
void update(int update_left, int update_right, int new_value, int node_id,
            int node_left, int node_right) {
  if (update_right < node_left || update_left > node_right)
    return;
  else if (update_left <= node_left && update_right >= node_right) {
    data[node_id] = new_value; // to update the value(if in the right rage or a
                               // single point;
  } else {
    if (data[node_id] >= 0) { // deal with previous node (to check the if there
                              // is previous vlue to update)
      data[node_id * 2 + 1] = data[node_id];
      data[node_id * 2 + 2] = data[node_id];
      // update(node_left,node_right,data[node_id],2*node_id+1,node_left,(node_left+node_right)/2);
      // update(node_left,node_right,data[node_id],2*node_id+2,(node_left+node_right)/2+1,node_right);
      data[node_id] = -1; // why set -1 (unfold it)
    }
    // update with update_left and update_right
    update(update_left, update_right, new_value, 2 * node_id + 1, node_left,
           (node_left + node_right) / 2);
    update(update_left, update_right, new_value, 2 * node_id + 2,
           (node_left + node_right) / 2 + 1, node_right);
  }
}
int query(int search_left, int search_right, int node_id, int node_left,
          int node_right) {
  if (search_right < node_left || search_left > node_right) {
    return MAXVAL; // not in the range, e.g. 1 1 2
  } else {
    if (data[node_id] != -1)
      return data[node_id]; // not unfold, how to know if we have the right node
    // if(search_left>=node_left&&search_right<=node_right) return
    // data[node_id];
    else {
      int left = query(search_left, search_right, 2 * node_id + 1, node_left,
                       (node_left + node_right) / 2);
      int right = query(search_left, search_right, 2 * node_id + 2,
                        (node_left + node_right) / 2 + 1, node_right);
      return min(left, right);
    }
  }
}

Error: -11

Fixed submission:

#include <math.h>
#include <stdio.h>
#define MAX 2147483647
int data[270500]; // the size is
int min(int a, int b) { return a > b ? b : a; }
// recursion and top to bottom
void update(int s_l, int s_r, int value, int node_id, int l, int r) {
  // printf("wei");
  // boundary case
  if (s_l > r || s_r < l)
    return;
  if (s_l <= l && s_r >= r) { // key case
    data[node_id] = value;
  }
  // unfold the parent
  if (data[node_id] != -1) {
    data[node_id * 2 + 1] = data[node_id];
    data[node_id * 2 + 2] = data[node_id];
    data[node_id] = -1;
  }

  update(s_l, s_r, value, node_id * 2 + 1, l, (l + r) / 2);
  update(s_l, s_r, value, node_id * 2 + 2, (l + r) / 2 + 1, r);
}

int query(int sl, int sr, int node_id, int l, int r) {
  if (sl > r || sr < l)
    return MAX;
  if (sl <= l && sr >= r) { // key case
    return data[node_id];
  }
  int left = query(sl, sr, node_id * 2 + 1, l, (l + r) / 2);
  int right = query(sl, sr, node_id * 2 + 2, (l + r) / 2 + 1, r);
  return min(left, right);
}
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  int N = 1;
  while (N < n)
    N = N * 2;
  for (int i = 0; i <= 2 * N - 2; i++) {
    data[i] = MAX;
  }
  // printf("wei");
  int temp = 0, a = 0, b = 0, c = 0;
  for (int i = 0; i < q; i++) {

    scanf("%d", &temp);
    if (temp == 0) {
      // printf("temp%d\\n",temp);
      scanf("%d %d %d", &a, &b, &c);
      // printf("Wei");
      update(a, b, c, 0, 0, N - 1);

    } else {
      scanf("%d %d", &a, &b);
      printf("%d\\n", query(a, b, 0, 0, N - 1));
    }
  }

  return 0;
}