alexjercan/bugnet huggingface dataset:
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;

int n, q;
const int N = 1 << 17;
const int INF = (1LL << 31LL) - 1;
int dat[2 * N - 1];

void init(int n_) {
  n = 1;
  while (n_ > n)
    n *= 2;
  for (int i = 0; i < n * 2 - 1; ++i)
    dat[i] = INF;
}

void update(int k, int a) {
  k += n - 1;
  dat[k] = a;

  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
}

int query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l)
    return INF;

  if (a <= l && r <= b)
    return dat[k];

  int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
  int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);

  return min(vl, vr);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> q;
  init(n);

  int c, x, y;
  for (int i = 0; i < q; ++i) {
    cin >> c >> x >> y;
    if (c == 0)
      update(x, y);
    else {
      y++;
      cout << query(x, y, 0, 0, n) << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

int n, q;
const int N = 100010;
const int INF = (1LL << 31LL) - 1;
int dat[2 * N - 1];

void init(int n_) {
  n = 1;
  while (n_ > n)
    n *= 2;
  for (int i = 0; i < n * 2 - 1; ++i)
    dat[i] = INF;
}

void update(int k, int a) {
  k += n - 1;
  dat[k] = a;

  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
}

int query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l)
    return INF;

  if (a <= l && r <= b)
    return dat[k];

  int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
  int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);

  return min(vl, vr);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> q;
  init(n);

  int c, x, y;
  for (int i = 0; i < q; ++i) {
    cin >> c >> x >> y;
    if (c == 0)
      update(x, y);
    else {
      y++;
      cout << query(x, y, 0, 0, n) << endl;
    }
  }

  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
const int N = 1 << 17;
typedef long long LL;
const int INF = (1LL << 31LL) - 1;
int n, q;
int dat[2 * N - 1];

void init() {
  int a = n;
  n = 1;
  while (n < a)
    n *= 2;
  for (int i = 0; i != n * 2 - 1; ++i)
    dat[i] = INF;
}

void update(int k, int a) {
  k += n - 1;
  dat[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
}

int query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l)
    return INF;

  if (a <= l && r <= b)
    return dat[k];
  else {
    int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);

    return min(vl, vr);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> q;
  init();

  int c, x, y;
  for (int i = 0; i < q; ++i) {
    cin >> c >> x >> y;
    if (c == 0)
      update(x, y);
    else {
      ++y;
      cout << query(x, y, 0, 0, n) << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
const int N = 100000;
typedef long long LL;
const LL INF = (1LL << 31LL) - 1;
int n, q;
int dat[2 * N - 1];

void init() {
  int a = n;
  n = 1;
  while (n < a)
    n *= 2;
  for (int i = 0; i != n * 2 - 1; ++i)
    dat[i] = INF;
}

void update(int k, int a) {
  k += n - 1;
  dat[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
}

int query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l)
    return INF;

  if (a <= l && r <= b)
    return dat[k];
  else {
    int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);

    return min(vl, vr);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> q;
  init();

  int c, x, y;
  for (int i = 0; i < q; ++i) {
    cin >> c >> x >> y;
    if (c == 0)
      update(x, y);
    else {
      ++y;
      cout << query(x, y, 0, 0, n) << endl;
    }
  }

  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
struct SegmentTree {
  int n_, n = 1;
  int MAX = 2147483647;
  vector<int> v;
  SegmentTree(int n_) : n_(n_) {
    while (n < n_)
      n *= 2; // 2の冪乗が扱いやすい
    v.assign(2 * n, MAX);
  }
  // k番目の要素をaに変更
  void update(int k, int a) {
    k += n - 1; // ノード番号にする
    v[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      v[k] = min(v[2 * k + 1], v[2 * k + 2]);
    }
  }
  // [a, b)の最小値,kはノード番号
  // query(a,b,0,0,n)を呼ぶ
  int query_(int a, int b, int k, int l, int r) {
    if (b <= l || r <= a)
      return MAX;
    if (a <= l && r <= b)
      return v[k];
    int vl = query_(a, b, 2 * k + 1, l, (l + r) / 2);
    int vr = query_(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }

  int query(int a, int b) { return query_(a, b, 0, 0, n); }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  SegmentTree seg(n);
  FOR(i, 0, q) {
    int com;
    int x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      seg.update(x, y);
    } else {
      cout << seg.query(x, y + 1) << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
struct SegmentTree {
  int n_, n = 1;
  int MAX = 2147483647;
  int v[202020];
  SegmentTree(int n_) : n_(n_) {
    while (n < n_)
      n *= 2; // 2の冪乗が扱いやすい
    FOR(i, 0, 2 * n) v[i] = MAX;
  }
  // k番目の要素をaに変更
  void update(int k, int a) {
    k += n - 1; // ノード番号にする
    v[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      v[k] = min(v[2 * k + 1], v[2 * k + 2]);
    }
  }
  // [a, b)の最小値,kはノード番号
  // query(a,b,0,0,n)を呼ぶ
  int query_(int a, int b, int k, int l, int r) {
    if (b <= l || r <= a)
      return MAX;
    if (a <= l && r <= b)
      return v[k];
    int vl = query_(a, b, 2 * k + 1, l, (l + r) / 2);
    int vr = query_(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }

  int query(int a, int b) { return query_(a, b, 0, 0, n); }
};
int main() {

  int n, q;
  cin >> n >> q;
  SegmentTree seg(n);
  FOR(i, 0, q) {
    int com;
    int x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      seg.update(x, y);
    } else {
      cout << seg.query(x, y + 1) << endl;
    }
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;

const int INF = (1LL << 31) - 1;

struct SegmentTree {
  int n;
  vector<int> v;

  SegmentTree(int n_, int x) : v(n_ * 4) {
    for (int i = 0; (1 << i) <= n_; ++i, n = 1 << i)
      ;
    for (int i = 0; i < n_ * 4; ++i)
      v[i] = x;
  }

  void set(int i, int x) {
    i += n - 1;
    v[i] = x;
    for (; i > 0;) {
      i = (i - 1) / 2;
      v[i] = min(v[2 * i + 1], v[2 * i + 2]);
    }
  }

  int find(int l, int r) { return find(l, r, 0, 0, n); }

  int find(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return INF;
    if (a <= l && r <= b) {
      return v[k];
    } else {
      int vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
      int vr = find(a, b, k * 2 + 2, (l + r) / 2, r);
      return min(vl, vr);
    }
  }
};

int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  SegmentTree st(n, INF);

  for (int i = 0; i < q; ++i) {
    // for (int i = 0; i < st.n * 2 - 1; ++i) printf(" %d", st.v[i]); puts("");
    int c, x, y;
    scanf("%d %d %d", &c, &x, &y);
    if (c == 0) {
      st.set(x, y);
    } else /*if (c == 1)*/ {
      printf("%d\\n", st.find(x, y + 1));
    }
  }

  return 0;
}

Error: -6
malloc(): corrupted top size


Fixed submission:

#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;

const int INF = (1LL << 31) - 1;

struct SegmentTree {
  int n;
  vector<int> v;

  SegmentTree(int n_, int x) : v(n_ * 4) {
    for (int i = 0; (1 << i) <= n_; ++i, n = 1 << i)
      ;
    for (int i = 0; i < n * 4; ++i)
      v[i] = x;
  }

  void set(int i, int x) {
    i += n - 1;
    v[i] = x;
    for (; i > 0;) {
      i = (i - 1) / 2;
      v[i] = min(v[2 * i + 1], v[2 * i + 2]);
    }
  }

  int find(int l, int r) { return find(l, r, 0, 0, n); }

  int find(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return INF;
    if (a <= l && r <= b) {
      return v[k];
    } else {
      int vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
      int vr = find(a, b, k * 2 + 2, (l + r) / 2, r);
      return min(vl, vr);
    }
  }
};

int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  SegmentTree st(n, INF);

  for (int i = 0; i < q; ++i) {
    // for (int i = 0; i < st.n * 2 - 1; ++i) printf(" %d", st.v[i]); puts("");
    int c, x, y;
    scanf("%d %d %d", &c, &x, &y);
    if (c == 0) {
      st.set(x, y);
    } else /*if (c == 1)*/ {
      printf("%d\\n", st.find(x, y + 1));
    }
  }

  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 100000000
#define MAXN 100010
#define INT_MAX 2147483647
typedef long long ll;

int n, q;
int dat[MAXN * 4];

// 初期化
void init(int n_) {
  n = 1;
  while (n < n_)
    n *= 2;
  for (int i = 0; i < 2 * n - 1; i++)
    dat[i] = INT_MAX;
}

// k番目の値をxに変更
void update(int k, int x) {
  k += n - 1;
  dat[k] = x;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
}

// [a, b)の最小値を求める
int query(int a, int b, int k, int l, int r) {
  if (a >= r || b <= l)
    return INT_MAX;
  if (a <= l && r <= b)
    return dat[k];
  int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
  int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(vl, vr);
}

int main(void) {
  cin >> n >> q;
  init(n);
  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      update(x, y);
    } else {
      cout << query(x, y + 1, 0, 0, n) << endl;
    }
    //        for (int i = 0; i < 2*n-1; i++) {
    //            cout << dat[i] << endl;
    //        }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 100000000
#define MAXN 100010
#define INT_MAX 2147483647
typedef long long ll;

int n, q;
int dat[MAXN * 2];

// 初期化
void init(int n_) {
  n = 1;
  while (n < n_)
    n *= 2;
  for (int i = 0; i < 2 * n - 1; i++)
    dat[i] = INT_MAX;
}

// k番目の値をxに変更
void update(int k, int x) {
  k += n - 1;
  dat[k] = x;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
}

// [a, b)の最小値を求める
int query(int a, int b, int k, int l, int r) {
  if (a >= r || b <= l)
    return INT_MAX;
  if (a <= l && r <= b)
    return dat[k];
  int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
  int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(vl, vr);
}

int main(void) {
  cin >> n >> q;
  init(n);
  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      update(x, y);
    } else {
      cout << query(x, y + 1, 0, 0, n) << endl;
    }
    //        for (int i = 0; i < 2*n-1; i++) {
    //            cout << dat[i] << endl;
    //        }
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;

const long long Mx = 0x7FFFFFFF;
long long n, q, x, y, m = 1;
long long a[300000];

void ud(long long x, long long y) {
  long long k = m + x - 1;
  a[k] = y;
  while (k > 0) {
    k = (k - 1) / 2;
    a[k] = min(a[k * 2 + 1], a[k * 2 + 2]);
  }
}

long long find(long long x, long long y, long long k, long long l,
               long long r) {
  if (x <= l && y >= r)
    return a[k];
  else if (x >= r || y <= l)
    return Mx;
  else {
    long long lm = find(x, y, k * 2 + 1, l, (l + r) / 2);
    long long rm = find(x, y, k * 2 + 2, (l + r) / 2, r);

    return min(lm, rm);
  }
}

int main() {
  cin >> n >> q;

  while (m < n)
    m *= 2;

  for (int i = 0; i < m * 2; i++)
    a[i] = Mx;

  for (int j = 0; j < q; j++) {
    int p;
    cin >> p;

    if (p == 0) {
      cin >> x >> y;
      ud(x, y);
    } else if (p == 1) {
      cin >> x >> y;
      cout << find(x, y + 1, 0, 0, m) << endl;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

const long long Mx = 0x7FFFFFFF;
long long n, q, x, y, m = 1;
long long a[200000];

void ud(long long x, long long y) {
  long long k = m + x - 1;
  a[k] = y;
  while (k > 0) {
    k = (k - 1) / 2;
    a[k] = min(a[k * 2 + 1], a[k * 2 + 2]);
  }
}

long long find(long long x, long long y, long long k, long long l,
               long long r) {
  if (x <= l && y >= r)
    return a[k];
  else if (x >= r || y <= l)
    return Mx;
  else {
    long long lm = find(x, y, k * 2 + 1, l, (l + r) / 2);
    long long rm = find(x, y, k * 2 + 2, (l + r) / 2, r);

    return min(lm, rm);
  }
}

int main() {
  cin >> n >> q;

  while (m < n)
    m *= 2;

  for (int i = 0; i < m * 2; i++)
    a[i] = Mx;

  for (int j = 0; j < q; j++) {
    int p;
    cin >> p;

    if (p == 0) {
      cin >> x >> y;
      ud(x, y);
    } else if (p == 1) {
      cin >> x >> y;
      cout << find(x, y + 1, 0, 0, m) << endl;
    }
  }

  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <climits>
#include <iostream>

using namespace std;

const int max_n = 1 << 17;
const int max_array = max_n * 2 - 1;

const int INF = 2147483647;

int dat[max_array];

void init() {
  for (int i = 0; i < max_array; i++) {
    dat[i] = INF;
  }
}

void update(int k, int x) {
  k += max_n - 1;
  dat[k] = x;

  while (k > 0) {
    k = (k - 1) / 2;

    dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
}

int find(int a, int b, int k, int l, int m) {

  if (m <= a || b <= l) {
    return INF;
  }
  if (a <= l && m <= b) {
    return dat[k];
  }
  int lv = find(a, b, k * 2 + 1, l, (l + m) / 2);
  int mv = find(a, b, k * 2 + 2, (l + m) / 2, m);
  return min(lv, mv);
}

int main() {
  int n, q;
  cin >> n >> q;

  init();

  for (int i = 0; i < q; i++) {
    int x, y, com;
    cin >> com >> x >> y;
    if (com == 0) {
      update(x, y);
    } else {
      cout << find(x, y + 1, 0, 0, max_n) << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <climits>
#include <iostream>

using namespace std;

const int max_n = 1 << 16;
const int max_array = max_n * 2 - 1;

const int INF = 2147483647;

int dat[max_array];

void init() {
  for (int i = 0; i < max_array; i++) {
    dat[i] = INF;
  }
}

void update(int k, int x) {
  k += max_n - 1;
  dat[k] = x;

  while (k > 0) {
    k = (k - 1) / 2;

    dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
}

int find(int a, int b, int k, int l, int m) {

  if (m <= a || b <= l) {
    return INF;
  }
  if (a <= l && m <= b) {
    return dat[k];
  }
  int lv = find(a, b, k * 2 + 1, l, (l + m) / 2);
  int mv = find(a, b, k * 2 + 2, (l + m) / 2, m);
  return min(lv, mv);
}

int main() {
  int n, q;
  cin >> n >> q;

  init();

  for (int i = 0; i < q; i++) {
    int x, y, com;
    cin >> com >> x >> y;
    if (com == 0) {
      update(x, y);
    } else {
      cout << find(x, y + 1, 0, 0, max_n) << endl;
    }
  }
}
Problem p02345 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;

int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  long A[100000];
  for (long i = 0; i < n; i++)
    A[i] = pow(2, 31) - 1;
  for (long i = 0; i < q; i++) {
    long c, x, y;
    scanf("%ld %ld %ld", &c, &x, &y);
    if (c == 0)
      A[x] = y;
    else
      printf("%ld\\n", *min_element(A + x, A + y + 1));
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;

int main() {
  long n, q;
  scanf("%d %d", &n, &q);
  long A[100000];
  for (long i = 0; i < n; i++)
    A[i] = pow(2, 31) - 1;
  for (long i = 0; i < q; i++) {
    long c, x, y;
    scanf("%ld %ld %ld", &c, &x, &y);
    if (c == 0)
      A[x] = y;
    else
      printf("%ld\\n", *min_element(A + x, A + y + 1));
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

const int MAX_N = 100010;

const int inf = 2147483647;
int dat[MAX_N * 4];
int n;

void init(int n_) {
  n = 1;
  while (n < n_)
    n *= 2; // 2のn乗に切り上げる
  // 全て inf で初期化したいとき
  for (int i = 0; i < n * 2; i++) {
    dat[i] = inf;
  }
  // 配列 a の要素で初期化したいとき
  // for(int i = n; i < n+n; i++){
  //     dat[i] = a[i-n];
  // }
  // for(int i=n-1; i>=1; i--){
  //     dat[i] = min(dat[i*2], dat[i*2+1]);
  // }
}

void update(int i, int x) {
  i += n;
  dat[i] = x;
  while (i > 0) {
    dat[i / 2] = min(dat[i], dat[i ^ 1]);
    i /= 2;
  }
}

int query(int a, int b, int i, int l, int r) {
  if (r <= a || b <= l)
    return inf;
  if (a <= l && r <= b)
    return dat[i];
  return min(query(a, b, i * 2, l, (l + r) / 2),
             query(a, b, i * 2 + 1, (l + r) / 2, r));
}

int query(int a, int b) { return query(a, b, 1, 0, n); }

int main() {
  int n, q;
  while (cin >> n >> q) {
    init(n);
    for (int i = 0; i < q; i++) {
      char c;
      int x, y;
      cin >> c >> x >> y;
      if (c == '0') {
        update(x, y);
      } else {
        cout << query(x, y + 1) << endl;
      }
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

const int MAX_N = 100010;

const int inf = 2147483647;
int dat[MAX_N * 2];
int n;

void init(int n_) {
  n = 1;
  while (n < n_)
    n *= 2; // 2のn乗に切り上げる
  // 全て inf で初期化したいとき
  for (int i = 0; i < n * 2; i++) {
    dat[i] = inf;
  }
  // 配列 a の要素で初期化したいとき
  // for(int i = n; i < n+n; i++){
  //     dat[i] = a[i-n];
  // }
  // for(int i=n-1; i>=1; i--){
  //     dat[i] = min(dat[i*2], dat[i*2+1]);
  // }
}

void update(int i, int x) {
  i += n;
  dat[i] = x;
  while (i > 0) {
    dat[i / 2] = min(dat[i], dat[i ^ 1]);
    i /= 2;
  }
}

int query(int a, int b, int i, int l, int r) {
  if (r <= a || b <= l)
    return inf;
  if (a <= l && r <= b)
    return dat[i];
  return min(query(a, b, i * 2, l, (l + r) / 2),
             query(a, b, i * 2 + 1, (l + r) / 2, r));
}

int query(int a, int b) { return query(a, b, 1, 0, n); }

int main() {
  int n, q;
  while (cin >> n >> q) {
    init(n);
    for (int i = 0; i < q; i++) {
      char c;
      int x, y;
      cin >> c >> x >> y;
      if (c == '0') {
        update(x, y);
      } else {
        cout << query(x, y + 1) << endl;
      }
    }
  }
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SIZE 200005
#define INF 2147483647

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int n;
int dat[1 << 19];

// 配列、木:0オリジン
// n_:元の数列の要素数
// n:修正後の配列要素数 木のサイズ:2*n-1
void init(int n_) {
  n = 1;
  while (n < n_)
    n *= 2;
  for (int i = 0; i < 2 * n - 1; i++)
    dat[i] = INF;
}

void update(int i, ll x) {
  i += n - 1;
  dat[i] = x;
  while (i > 0) {
    i = (i - 1) / 2;
    dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
  }
}

//[a,b)のmin 節点k[l,r)について調べる
int find(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) {
    return INF;
  } else if (a <= l && r <= b) {
    return dat[k];
  } else {
    ll v1 = find(a, b, 2 * k + 1, l, (l + r) / 2);
    ll v2 = find(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(v1, v2);
  }
}

int main() {
  int q, m;
  scanf("%d %d", &m, &q);
  init(m);
  int com, x;
  ll y;
  for (int i = 0; i < q; i++) {
    scanf("%d%d%d", &com, &x, &y);
    if (com == 0) {
      update(x, y);
    } else {
      printf("%d\\n", find(x, y + 1, 0, 0, n));
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SIZE 100005
#define INF 2147483647LL

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int n;
int dat[SIZE * 2];

// 配列、木:0オリジン
// n_:元の数列の要素数
// n:修正後の配列要素数 木のサイズ:2*n-1
void init(int n_) {
  n = 1;
  while (n < n_)
    n *= 2;
  for (int i = 0; i < 2 * n - 1; i++)
    dat[i] = INF;
}

void update(int i, ll x) {
  i += n - 1;
  dat[i] = x;
  while (i > 0) {
    i = (i - 1) / 2;
    dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
  }
}

//[a,b)のmin 節点k[l,r)について調べる
int find(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) {
    return INF;
  } else if (a <= l && r <= b) {
    return dat[k];
  } else {
    ll v1 = find(a, b, 2 * k + 1, l, (l + r) / 2);
    ll v2 = find(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(v1, v2);
  }
}

int main() {
  int q, m;
  scanf("%d %d", &m, &q);
  init(m);
  int com, x;
  ll y;
  for (int i = 0; i < q; i++) {
    scanf("%d%d%d", &com, &x, &y);
    if (com == 0) {
      update(x, y);
    } else {
      printf("%d\\n", find(x, y + 1, 0, 0, n));
    }
  }
  return 0;
}