prithivMLmods/Coder-Stat huggingface dataset:
Problem p02345 (C++)

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)

typedef ll V;
const V INF_V = INT_MAX;
const int ME = 16;
const int N = 1 << ME;
class RMQ_segtree {
public:
  V dat[2 * N - 1];
  RMQ_segtree() { REP(i, 2 * N - 1) dat[i] = INF_V; }

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

  V recursion(int a, int b, int k, int l, int r) {
    //????°?????¨??????¨????????°??¢??°
    if (r <= a || b <= l)
      return INF_V;
    if (a <= l && r <= b)
      return dat[k];
    else {
      V vl = recursion(a, b, 2 * k + 1, l, (l + r) / 2);
      V vr = recursion(a, b, 2 * k + 2, (l + r) / 2, r);
      return min(vl, vr);
    }
  }

  V minimum(int a, int b) {
    //??????[a, b)???????°????
    return recursion(a, b, 0, 0, N);
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  RMQ_segtree rmq;
  REP(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      rmq.update(x, y);
    } else {
      cout << rmq.minimum(x, y + 1) << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)

typedef ll V;
const V INF_V = INT_MAX;
const int ME = 17;
const int N = 1 << ME;
class RMQ_segtree {
public:
  V dat[2 * N - 1];
  RMQ_segtree() { REP(i, 2 * N - 1) dat[i] = INF_V; }

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

  V recursion(int a, int b, int k, int l, int r) {
    //????°?????¨??????¨????????°??¢??°
    if (r <= a || b <= l)
      return INF_V;
    if (a <= l && r <= b)
      return dat[k];
    else {
      V vl = recursion(a, b, 2 * k + 1, l, (l + r) / 2);
      V vr = recursion(a, b, 2 * k + 2, (l + r) / 2, r);
      return min(vl, vr);
    }
  }

  V minimum(int a, int b) {
    //??????[a, b)???????°????
    return recursion(a, b, 0, 0, N);
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  RMQ_segtree rmq;
  REP(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      rmq.update(x, y);
    } else {
      cout << rmq.minimum(x, y + 1) << endl;
    }
  }
  return 0;
}
Problem p02345 (C++)

Buggy submission (status: Runtime Error):
#include <climits>
#include <cstdio>
#include <iostream>
#define MAX 200000
#define INF INT_MAX
using namespace std;

int D[MAX];
int n = 1;
int inf;

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

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 D[k];

  int vleft, vright;
  vleft = query(a, b, 2 * k + 1, l, (l + r) / 2);
  vright = query(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(vleft, vright);
}

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

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

int main() {
  int q, com, x, y, n_, min;
  cin >> n_ >> q;
  initRMQ(n_);
  for (int i = 0; i < q; i++) {
    cin >> com >> x >> y;
    if (com == 0)
      update(x, y);
    else
      cout << findMin(x, y) << endl;
  }
  return 0;
}


Fixed submission:
#include <climits>
#include <cstdio>
#include <iostream>
#define MAX 300000
#define INF INT_MAX
using namespace std;

int D[MAX];
int n = 1;
int inf;

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

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 D[k];

  int vleft, vright;
  vleft = query(a, b, 2 * k + 1, l, (l + r) / 2);
  vright = query(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(vleft, vright);
}

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

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

int main() {
  int q, com, x, y, n_, min;
  cin >> n_ >> q;
  initRMQ(n_);
  for (int i = 0; i < q; i++) {
    cin >> com >> x >> y;
    if (com == 0)
      update(x, y);
    else
      cout << findMin(x, y) << endl;
  }
  return 0;
}
Problem p02345 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;

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

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 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, (r + l) / 2);
    int vr = query(a, b, k * 2 + 2, (r + l) / 2, r);
    return min(vl, vr);
  }
}

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

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

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

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;

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

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 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, (r + l) / 2);
    int vr = query(a, b, k * 2 + 2, (r + l) / 2, r);
    return min(vl, vr);
  }
}

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

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

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

  return 0;
}
Problem p02345 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;

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

struct segtree {
  int n;
  int data[2620]; // 143];
  segtree(int n_) {
    n = 1;
    while (n_ > n)
      n *= 2;
    for (int i = 0; i < n * 2 - 1; i++)
      data[i] = INF;
  }
  void update(int k, int a) {
    k += n - 1;
    data[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = min(data[2 * k + 1], data[2 * k + 2]);
    }
  }
  int query(int a, int b) { return query(a, b, 0, 0, n); }
  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 data[k];
    return min(query(a, b, 2 * k + 1, l, (l + r) / 2),
               query(a, b, 2 * k + 2, (l + r) / 2, r));
  }
};

int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  segtree st(n);
  for (int i = 0; i < q; i++) {
    int cmd, x, y;
    scanf("%d %d %d", &cmd, &x, &y);
    if (cmd == 0)
      st.update(x, y);
    else if (cmd == 1)
      printf("%d\n", st.query(x, y + 1));
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;

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

struct segtree {
  int n;
  int data[262143];
  segtree(int n_) {
    n = 1;
    while (n_ > n)
      n *= 2;
    for (int i = 0; i < n * 2 - 1; i++)
      data[i] = INF;
  }
  void update(int k, int a) {
    k += n - 1;
    data[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = min(data[2 * k + 1], data[2 * k + 2]);
    }
  }
  int query(int a, int b) { return query(a, b, 0, 0, n); }
  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 data[k];
    return min(query(a, b, 2 * k + 1, l, (l + r) / 2),
               query(a, b, 2 * k + 2, (l + r) / 2, r));
  }
};

int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  segtree st(n);
  for (int i = 0; i < q; i++) {
    int cmd, x, y;
    scanf("%d %d %d", &cmd, &x, &y);
    if (cmd == 0)
      st.update(x, y);
    else if (cmd == 1)
      printf("%d\n", st.query(x, y + 1));
  }
  return 0;
}
Problem p02345 (C++)

Buggy submission (status: Runtime Error):
// #define LOCAL

#include <algorithm>
#include <assert.h>
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)

// #define int long long
typedef long long ll;

const ll INF = 1e18;

using namespace std;

const int MAX_N = 130100;
int n, dat[2 * MAX_N - 1];

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

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 INT_MAX;
  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);
  }
}

signed main() {
#ifdef LOCAL
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif

  int N, Q;
  int com, x, y;

  cin >> N >> Q;
  init(N + 100);
  REP(i, Q) {
    cin >> com >> x >> y;
    if (com == 0) {
      update(x, y);
    } else {
      cout << query(x, y + 1, 0, 0, n) << endl;
    }
  }
}

Fixed submission:
// #define LOCAL

#include <algorithm>
#include <assert.h>
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)

// #define int long long
typedef long long ll;

const ll INF = 1e18;

using namespace std;

const int MAX_N = 300100;
int n, dat[2 * MAX_N - 1];

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

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 INT_MAX;
  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);
  }
}

signed main() {
#ifdef LOCAL
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif

  int N, Q;
  int com, x, y;

  cin >> N >> Q;
  init(N + 100);
  REP(i, Q) {
    cin >> com >> x >> y;
    if (com == 0) {
      update(x, y);
    } else {
      cout << query(x, y + 1, 0, 0, n) << endl;
    }
  }
}
Problem p02345 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int MAX_N = 100000;

int n;
vector<int> dat(2 * MAX_N - 1, INT_MAX);

void init(int N) {
  n = 1;
  while (n < N) {
    n *= 2;
  }
}

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

int find(int x, int y, int k, int l, int r) {
  if (r <= x || l >= y) {
    return INT_MAX;
  }
  if (r <= y && l >= x) {
    return dat[k];
  } else {
    int vl = find(x, y, 2 * k + 1, l, (l + r) / 2);
    int vr = find(x, y, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
}

int main() {
  int N, q, command, x, y;

  cin >> N >> q;
  init(N);

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

Fixed submission:
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int MAX_N = 100000;

int n;
vector<int> dat(4 * MAX_N, INT_MAX);

void init(int N) {
  n = 1;
  while (n < N) {
    n *= 2;
  }
}

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

int find(int x, int y, int k, int l, int r) {
  if (r <= x || l >= y) {
    return INT_MAX;
  }
  if (r <= y && l >= x) {
    return dat[k];
  } else {
    int vl = find(x, y, 2 * k + 1, l, (l + r) / 2);
    int vr = find(x, y, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
}

int main() {
  int N, q, command, x, y;

  cin >> N >> q;
  init(N);

  for (int i = 0; i < q; i++) {
    cin >> command >> x >> y;
    if (command) {
      cout << find(x, y + 1, 0, 0, n) << endl;
    } else {
      update(x, y);
    }
  }
  return 0;
}
Problem p02345 (C++)

Buggy submission (status: 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 * 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;
}

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 * 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;
}
Problem p02345 (C++)

Buggy submission (status: 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[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;
}


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[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;
}
Problem p02345 (C++)

Buggy submission (status: Runtime Error):
#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;
      }
    }
  }
}

Fixed submission:
#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;
      }
    }
  }
}
Problem p02345 (C++)

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

struct RMQ {
  static const int MAXN = 100000;
  int n;
  int dat[2 * MAXN - 1];
  RMQ(int n_) { init(n_); }
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    for (int i = 0; i < 2 * n - 1; i++)
      dat[i] = INT_MAX;
  }
  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 INT_MAX;
    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 query(int a, int b) { return query(a, b, 0, 0, n); }
};
int main() {
  int n, q;
  cin >> n >> q;
  RMQ rmq(n);
  for (int i = 0; i < q; i++) {
    int c, x, y;
    cin >> c >> x >> y;
    if (c)
      cout << rmq.query(x, y + 1) << endl;
    else
      rmq.update(x, y);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

struct RMQ {
  static const int MAX_N = 1 << 17;
  int n, dat[2 * MAX_N - 1];
  // RMQ(){}
  RMQ(int n_) { init(n_); }
  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    for (int i = 0; i < 2 * n - 1; i++)
      dat[i] = INT_MAX;
  }
  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 INT_MAX;
    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 query(int a, int b) { return query(a, b, 0, 0, n); }
};
int main() {
  int n, q;
  cin >> n >> q;
  RMQ rmq(n);
  for (int i = 0; i < q; i++) {
    int c, x, y;
    cin >> c >> x >> y;
    if (c)
      cout << rmq.query(x, y + 1) << endl;
    else
      rmq.update(x, y);
  }
  return 0;
}
Problem p02345 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#define N (1 << 18)
#define INF 2147483647
using namespace std;
void Update(int, int);
int Find(int, int, int, int, int);
int tree[N], n, N1 = N;
int main() {
  int q, com, x, y;
  if (N1 % 2 == 1)
    N1 -= 1;
  cin >> n >> q;
  for (int i = 0; i < 2 * n - 1; i++)
    Update(i, INF);
  while (q--) {
    cin >> com >> x >> y;
    if (com == 0)
      Update(x, y);
    else {
      int r = Find(x, y + 1, 0, 0, N1 / 2);
      cout << r << endl;
    }
  }
  return 0;
}
void Update(int x, int y) {
  x += N1 / 2 - 1;
  tree[x] = y;
  while (x > 0) {
    x = (x - 1) / 2;
    tree[x] = min(tree[x * 2 + 1], tree[x * 2 + 2]);
  }
}
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 tree[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);
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#define N (1 << 19)
#define INF 2147483647
using namespace std;
void Update(int, int);
int Find(int, int, int, int, int);
int tree[N], n, N1 = N;
int main() {
  int q, com, x, y;
  if (N1 % 2 == 1)
    N1 -= 1;
  cin >> n >> q;
  for (int i = 0; i < 2 * n - 1; i++)
    Update(i, INF);
  while (q--) {
    cin >> com >> x >> y;
    if (com == 0)
      Update(x, y);
    else {
      int r = Find(x, y + 1, 0, 0, N1 / 2);
      cout << r << endl;
    }
  }
  return 0;
}
void Update(int x, int y) {
  x += N1 / 2 - 1;
  tree[x] = y;
  while (x > 0) {
    x = (x - 1) / 2;
    tree[x] = min(tree[x * 2 + 1], tree[x * 2 + 2]);
  }
}
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 tree[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);
  }
}
Problem p02345 (C++)

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

template <typename T> struct SegmentTree {
  struct Node {
    T v;
    Node(T v) : v(v) {}
    Node operator*(const Node &r) const { return Node(min(v, r.v)); }
  };

  Node e = Node((1ll << 31) - 1);
  size_t n;
  vector<Node> seg;

  SegmentTree(size_t size)
      : n(1 << (32 - __builtin_clz(size - 1))), seg(2 * n, e) {}

  void update(int k, const Node &x) {
    for (seg[k + n] = x, k = (k + n) / 2; k; k <<= 1) {
      seg[k] = seg[2 * k] * seg[2 * k + 1];
    }
  }

  Node query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return e;
    if (a <= l && r <= b)
      return seg[k];
    return query(a, b, 2 * k, l, (l + r) / 2) *
           query(a, b, 2 * k + 1, (l + r) / 2, r);
  }

  void update(int k, T x) { update(k, Node(x)); }

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

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

  SegmentTree<int> seg(n);
  while (q--) {
    int c, x, y;
    cin >> c >> x >> y;

    if (c) {
      cout << seg.query(x, y + 1) << endl;
    } else {
      seg.update(x, y);
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

template <typename T> struct SegmentTree {
  struct Node {
    T v;
    Node(T v) : v(v) {}
    Node operator*(const Node &r) const { return Node(min(v, r.v)); }
  };

  Node e = Node((1ll << 31) - 1);
  size_t n;
  vector<Node> seg;

  SegmentTree(size_t size)
      : n(1 << (32 - __builtin_clz(size - 1))), seg(2 * n, e) {}

  void update(int k, const Node &x) {
    for (seg[k + n] = x, k = (k + n) / 2; k; k >>= 1) {
      seg[k] = seg[2 * k] * seg[2 * k + 1];
    }
  }

  Node query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return e;
    if (a <= l && r <= b)
      return seg[k];
    return query(a, b, 2 * k, l, (l + r) / 2) *
           query(a, b, 2 * k + 1, (l + r) / 2, r);
  }

  void update(int k, T x) { update(k, Node(x)); }

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

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

  SegmentTree<int> seg(n);
  while (q--) {
    int c, x, y;
    cin >> c >> x >> y;

    if (c) {
      cout << seg.query(x, y + 1) << endl;
    } else {
      seg.update(x, y);
    }
  }
}
Problem p02345 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02345 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>
using namespace std;

int n, q;
int a[400005], b[400005], com[400005], c[400005], d[400005];
int N = 2147483648 - 1;
int sa;

void update(int x, int y) {
  x += sa;
  a[x] = y;
  while (x > 0) {
    x = (x - 1) / 2;
    a[x] = min(a[x * 2 + 1], a[x * 2 + 2]);
  }
}

int find(int x, int z, int k, int l, int r) {
  if (x <= l && r <= z) {
    return a[k];
  }
  if (r <= x || z <= l)
    return N;
  else {
    int vl = find(x, z, k * 2 + 1, l, (l + r) / 2);
    int vr = find(x, z, k * 2 + 2, (l + r) / 2, r);
    // printf("%d %d %d\n",k,vl,vr);
    return min(vl, vr);
  }
}

int pow(int x) {
  int i = 1;
  while (true) {
    if (i <= x && x < (i * 2))
      return (i * 2);
    else
      i *= 2;
  }
}

int main() {

  scanf("%d%d", &n, &q);

  for (int i = 0; i < q; i++) {
    scanf("%d%d%d", &com[i], &c[i], &d[i]);
  }

  sa = pow(n) - 1;
  int ni = 4 * sa;

  for (int i = 0; i < ni; i++) {
    a[i] = N;
  }

  for (int i = 0; i < q; i++) {
    if (com[i] == 0) {
      update(c[i], d[i]);
    } else {
      printf("%d\n", (find(c[i], d[i] + 1, 0, 0, sa + 1)));
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <stdio.h>
using namespace std;

int n, q;
int a[4000005], com[4000005], c[4000005], d[4000005];
int N = 2147483648 - 1;
int sa;

void update(int x, int y) {
  x += sa;
  a[x] = y;
  while (x > 0) {
    x = (x - 1) / 2;
    a[x] = min(a[x * 2 + 1], a[x * 2 + 2]);
  }
}

int find(int x, int z, int k, int l, int r) {
  if (x <= l && r <= z) {
    return a[k];
  }
  if (r <= x || z <= l)
    return N;
  else {
    int vl = find(x, z, k * 2 + 1, l, (l + r) / 2);
    int vr = find(x, z, k * 2 + 2, (l + r) / 2, r);
    // printf("%d %d %d\n",k,vl,vr);
    return min(vl, vr);
  }
}

int pow(int x) {
  int i = 1;
  while (true) {
    if (i <= x && x < (i * 2))
      return (i * 2);
    else
      i *= 2;
  }
}

int main() {

  scanf("%d%d", &n, &q);

  for (int i = 0; i < q; i++) {
    scanf("%d%d%d", &com[i], &c[i], &d[i]);
  }

  sa = pow(n) - 1;
  int ni = 4 * sa;

  for (int i = 0; i < ni; i++) {
    a[i] = N;
  }

  for (int i = 0; i < q; i++) {
    if (com[i] == 0) {
      update(c[i], d[i]);
    } else {
      printf("%d\n", (find(c[i], d[i] + 1, 0, 0, sa + 1)));
    }
  }

  return 0;
}
Problem p02345 (C++)

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

const int INF = 0x7fffffff;

int st[1 << 17];

void init(int n) {
  int nn = 1;
  while (nn < n)
    nn *= 2;
  fill(st, st + 2 * nn - 1, INF);
}

void update(int i, int a, int k, int l, int r) {
  if (i < l || r <= i)
    return;
  if (r - l == 1)
    st[k] = a;
  else {
    int chl = 2 * k + 1;
    int chr = 2 * k + 2;
    update(i, a, chl, l, (l + r) / 2);
    update(i, a, chr, (l + r) / 2, r);
    st[k] = min(st[chl], st[chr]);
  }
}

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 st[k];
  int res_l = find(a, b, 2 * k + 1, l, (l + r) / 2);
  int res_r = find(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(res_l, res_r);
}

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

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

const int INF = 0x7fffffff;

int st[1 << 18];

void init(int n) {
  int nn = 1;
  while (nn < n)
    nn *= 2;
  fill(st, st + 2 * nn - 1, INF);
}

void update(int i, int a, int k, int l, int r) {
  if (i < l || r <= i)
    return;
  if (r - l == 1)
    st[k] = a;
  else {
    int chl = 2 * k + 1;
    int chr = 2 * k + 2;
    update(i, a, chl, l, (l + r) / 2);
    update(i, a, chr, (l + r) / 2, r);
    st[k] = min(st[chl], st[chr]);
  }
}

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 st[k];
  int res_l = find(a, b, 2 * k + 1, l, (l + r) / 2);
  int res_r = find(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(res_l, res_r);
}

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

  return 0;
}
Problem p02345 (C++)

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

template <typename T, int M> struct RMQ {
  T arr[M];
  T INF;
  int N;

  RMQ(int N_, T INF_) {
    INF = INF_;
    for (int j = 0; j < 2 * M; ++j) {
      arr[j] = INF;
    }

    N = 1;
    while (N < N_)
      N *= 2;
  }

  void update(int x, int a) {
    int ind = N - 1 + x;

    arr[ind] = a;

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

  T query(int x, int y) { return query_(x, y, 0, 0, N); }

  T query_(int x, int y, int v, int l, int r) {
    if (y <= l || r <= x)
      return INF;

    if (x <= l && r <= y)
      return arr[v];

    T vl = query_(x, y, 2 * v + 1, l, (l + r) / 2);
    T vr = query_(x, y, 2 * v + 2, (l + r) / 2, r);

    return vl < vr ? vl : vr;
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  RMQ<int, 300000> rmq(n, ((1 << 30) - 1) * 2 + 1);

  for (int j = 0; j < q; ++j) {
    int com, x, y;
    cin >> com >> x >> y;

    if (com == 0) {
      rmq.update(x, y);
    }

    if (com == 1) {
      int res = rmq.query(x, y + 1);
      cout << res << endl;
    }
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

template <typename T, int M> struct RMQ {
  T arr[M];
  T INF;
  int N;

  RMQ(int N_, T INF_) {
    INF = INF_;
    for (int j = 0; j < M; ++j) {
      arr[j] = INF;
    }

    N = 1;
    while (N < N_)
      N *= 2;
  }

  void update(int x, int a) {
    int ind = N - 1 + x;

    arr[ind] = a;

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

  T query(int x, int y) { return query_(x, y, 0, 0, N); }

  T query_(int x, int y, int v, int l, int r) {
    if (y <= l || r <= x)
      return INF;

    if (x <= l && r <= y)
      return arr[v];

    T vl = query_(x, y, 2 * v + 1, l, (l + r) / 2);
    T vr = query_(x, y, 2 * v + 2, (l + r) / 2, r);

    return vl < vr ? vl : vr;
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  RMQ<int, 300000> rmq(n, ((1 << 30) - 1) * 2 + 1);

  for (int j = 0; j < q; ++j) {
    int com, x, y;
    cin >> com >> x >> y;

    if (com == 0) {
      rmq.update(x, y);
    }

    if (com == 1) {
      int res = rmq.query(x, y + 1);
      cout << res << endl;
    }
  }

  return 0;
}
Problem p02345 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define INF 100000005
#define MAX 100001
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int, int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int inf = 2147483647;

int n, dat[2 * MAX];
void init(int m) {
  n = 1;
  while (n < m)
    n *= 2;
  for (int i = 0; i < 2 * n; i++)
    dat[i] = inf;
}

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

int query(int a, int b, int k, int l, int r) {
  if (b <= l || r <= a)
    return inf;
  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() {
  int m, q, c, x, y, ans;
  scanf("%d%d", &m, &q);
  init(m);
  while (q--) {
    scanf("%d%d%d", &c, &x, &y);
    if (!c)
      change(x, y);
    else
      printf("%d\n", query(x, y + 1, 0, 0, n));
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define INF 100000005
#define MAX 100001
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int, int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int inf = 2147483647;

int n, dat[10 * MAX];
void init(int m) {
  n = 1;
  while (n < m)
    n *= 2;
  for (int i = 0; i < 2 * n; i++)
    dat[i] = inf;
}

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

int query(int a, int b, int k, int l, int r) {
  if (b <= l || r <= a)
    return inf;
  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() {
  int m, q, c, x, y, ans;
  scanf("%d%d", &m, &q);
  init(m);
  while (q--) {
    scanf("%d%d%d", &c, &x, &y);
    if (!c)
      change(x, y);
    else
      printf("%d\n", query(x, y + 1, 0, 0, n));
  }
  return 0;
}
Problem p02345 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

#define MAX_N 100001

int N, dat[2 * MAX_N - 1];
static const int maxi = pow(2, 31) - 1;

void init(int n) {
  N = 1;
  while (N < n)
    N *= 2;

  fill_n(dat, 2 * N - 1, maxi);
}

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 maxi;
  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);
}

void printv(int v[], int len) {
  for (int i = 0; i < len; i++)
    cout << " " << v[i];
  cout << endl;
}

int main() {
  int n, q, com, x, y;
  cin >> n >> q;
  init(n);
  while (q-- > 0) {
    //		printv(dat, N);
    cin >> com >> x >> y;
    if (com == 0)
      update(x, y);
    else
      cout << query(x, y + 1, 0, 0, N) << endl;
    ;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

#define MAX_N 200000

int N, dat[2 * MAX_N - 1];
static const int maxi = pow(2, 31) - 1;

void init(int n) {
  N = 1;
  while (N < n)
    N *= 2;

  fill_n(dat, 2 * N - 1, maxi);
}

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 maxi;
  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);
}

void printv(int v[], int len) {
  for (int i = 0; i < len; i++)
    cout << " " << v[i];
  cout << endl;
}

int main() {
  int n, q, com, x, y;
  cin >> n >> q;
  init(n);
  while (q-- > 0) {
    //		printv(dat, N);
    cin >> com >> x >> y;
    if (com == 0)
      update(x, y);
    else
      cout << query(x, y + 1, 0, 0, N) << endl;
    ;
  }
  return 0;
}
Problem p02345 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <limits.h>
using namespace std;
int inf = INT_MAX;
int dat[200001];
int n, q;
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 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) {
  // cout << a<< b<< k<<l<<r <<endl;
  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);
    // cout << vl << ":" <<vr << endl;
    return min(vl, vr);
  }
}

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

Fixed submission:
#include <iostream>
#include <limits.h>
using namespace std;
int inf = INT_MAX;
int dat[400004];
int n, q;
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 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) {
  // cout << a<< b<< k<<l<<r <<endl;
  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);
    // cout << vl << ":" <<vr << endl;
    return min(vl, vr);
  }
}

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

typedef long long ll;
#define pb push_back

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, s, n) for (int i = s; i < (n); ++i)
#define rev(i, n) for (int i = (n); i > 0; --i)
#define INF (1e9 + 1e9)

/* SegTree
   http://codeforces.com/blog/entry/18051
*/
class SegTree {
public:
  vector<int> t;
  int n;
  SegTree(int n) : n(n) {
    t.resize(1e5);
    fill(t.begin(), t.end(), INT_MAX);
    build();
  }

  void build() { rev(i, n - 1) t[i] = min(t[i << 1], t[i << 1 | 1]); }
  void modify(int p, int value) {
    for (t[p += n] = value; p > 1; p >>= 1)
      t[p >> 1] = min(t[p], t[p ^ 1]);
  }
  int query(int l, int r) { // [l,r)
    int res = INT_MAX;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1)
        res = min(res, t[l++]);
      if (r & 1)
        res = min(res, t[--r]);
    }
    return res;
  }
};

int main() {
  int N, Q;
  cin >> N >> Q;

  SegTree st(N);

  vector<int> C, X, Y;
  rep(i, Q) {
    int c, x, y;
    cin >> c >> x >> y;
    C.pb(c);
    X.pb(x);
    Y.pb(y);
  }

  rep(i, Q) if (C[i] == 0) st.modify(X[i], Y[i]);
  else cout << st.query(X[i], Y[i] + 1) << endl;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

typedef long long ll;
#define pb push_back

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, s, n) for (int i = s; i < (n); ++i)
#define rev(i, n) for (int i = (n); i > 0; --i)
#define INF (1e9 + 1e9)

/* SegTree
   http://codeforces.com/blog/entry/18051
*/
class SegTree {
public:
  vector<int> t;
  int n;
  SegTree(int n) : n(n) {
    t.resize(n << 1);
    fill(t.begin(), t.end(), INT_MAX);
    build();
  }

  void build() { rev(i, n - 1) t[i] = min(t[i << 1], t[i << 1 | 1]); }
  void modify(int p, int value) {
    for (t[p += n] = value; p > 1; p >>= 1)
      t[p >> 1] = min(t[p], t[p ^ 1]);
  }
  int query(int l, int r) { // [l,r)
    int res = INT_MAX;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1)
        res = min(res, t[l++]);
      if (r & 1)
        res = min(res, t[--r]);
    }
    return res;
  }
};

int main() {
  int N, Q;
  cin >> N >> Q;

  SegTree st(N);

  vector<int> C, X, Y;
  rep(i, Q) {
    int c, x, y;
    cin >> c >> x >> y;
    C.pb(c);
    X.pb(x);
    Y.pb(y);
  }

  rep(i, Q) if (C[i] == 0) st.modify(X[i], Y[i]);
  else cout << st.query(X[i], Y[i] + 1) << endl;
}