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

// Segment Tree
//  RMQ
#include <climits>
#include <cstdio>
#include <iostream>
using namespace std;
// const int MAX_N = 1 << 17;
const int MAX_N = 200022;

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

int init(int n_) {
  n = 1;

  while (n < n_)
    n *= 2;

  for (int i = 0; i < 2 * n - 1; i++)
    dat[i] = INT_MAX;

  return n;
}

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) {
    // cout<<a<<" DD "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
    return INT_MAX;
  }

  if (a <= l && r <= b) {
    // cout<<a<<" c "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
    // cout<<dat[k]<<endl;
    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<<a<<" b "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
    // cout<<vl<<" b "<<vr<<endl;
    return min(vl, vr);
  }
}

int main() {
  int n, q, com, x, y;

  cin >> n >> q;

  n = init(n);

  for (int i = 0; i < q; i++) {
    scanf("%d %d %d", &com, &x, &y);
    if (com) {
      printf("%d\\n", query(x, y + 1, 0, 0, n));
    } else {
      update(x, y);
    }
    // for(int i = 0; i < n*2; i++)
    // cout<<i<<" "<<dat[i]<<endl;
  }

  return 0;
}


Error: 0

Fixed submission:

// Segment Tree
//  RMQ
#include <climits>
#include <cstdio>
#include <iostream>
using namespace std;
// const int MAX_N = 1 << 17;
const int MAX_N = 100022;

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

int init(int n_) {
  n = 1;

  while (n < n_)
    n *= 2;

  for (int i = 0; i < 2 * n - 1; i++)
    dat[i] = INT_MAX;

  return n;
}

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) {
    // cout<<a<<" DD "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
    return INT_MAX;
  }

  if (a <= l && r <= b) {
    // cout<<a<<" c "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
    // cout<<dat[k]<<endl;
    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<<a<<" b "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
    // cout<<vl<<" b "<<vr<<endl;
    return min(vl, vr);
  }
}

int main() {
  int n, q, com, x, y;

  cin >> n >> q;

  n = init(n);

  for (int i = 0; i < q; i++) {
    scanf("%d %d %d", &com, &x, &y);
    if (com) {
      printf("%d\\n", query(x, y + 1, 0, 0, n));
    } else {
      update(x, y);
    }
    // for(int i = 0; i < n*2; i++)
    // cout<<i<<" "<<dat[i]<<endl;
  }

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

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

template <typename T> class SegmentTree {
  using func_t = function<T(T, T)>;
  const int n;
  const T id;
  func_t merge;
  vector<T> data;
  int size(int n) {
    int res;
    for (res = 1; res < n; res <<= 1)
      ;
    return res;
  }
  T sub(int l, int r, int node, int lb, int ub) {
    if (ub <= l || r <= lb)
      return id;
    if (l <= lb && ub <= r)
      return data[node];
    return merge(sub(l, r, node * 2, lb, (lb + ub) / 2),
                 sub(l, r, node * 2 + 1, (lb + ub) / 2, ub));
  }

public:
  SegmentTree(int n_, T id_, func_t merge_)
      : n(size(n_)), id(id_), merge(merge_), data(size(n_) * 2, id_) {}
  SegmentTree(vector<T> data_, T id_, func_t merge_)
      : n(size(data_.size())), id(id_), merge(merge_),
        data(size(data_.size()) * 2, id_) {
    for (int i = 0; i < data_.size(); i++)
      data[i + n] = data_[i];
    for (int i = n - 1; i >= 0; i--)
      data[i] = merge(data[i * 2], data[i * 2 + 1]);
  }
  void Update(int p, T val) {
    assert(0 <= p && p < n);
    p += n;
    data[p] = val;
    while (p >>= 1)
      data[p] = merge(data[p * 2], data[p * 2 + 1]);
  }
  T Find(int l, int r) { return sub(l, r + 1, 1, 0, n); }
};

int main() {
  int n, q;
  int com, x, y;
  cin >> n >> q;
  SegmentTree<int> st(n, 0x7fffffff,
                      [](int a, int b) { return a <= b ? a : b; });
  for (int i = 0; i < q; i++) {
    cin >> com >> x >> y;
    if (com)
      cout << st.Find(x, y) << endl;
    else
      st.Update(x, y);
  }
  return 0;
}

Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

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

template <typename T> class SegmentTree {
  using func_t = function<T(T, T)>;
  const int n;
  const T id;
  func_t merge;
  vector<T> data;
  T sub(int l, int r, int node, int lb, int ub) {
    if (ub <= l || r <= lb)
      return id;
    if (l <= lb && ub <= r)
      return data[node];
    T vl = sub(l, r, node * 2 + 0, lb, (lb + ub) / 2);
    T vr = sub(l, r, node * 2 + 1, (lb + ub) / 2, ub);
    return merge(vl, vr);
  }
  int size(int n) { return n == 1 ? n : size((n + 1) / 2) * 2; }

public:
  SegmentTree(int n, T id, func_t merge)
      : n(size(n)), id(id), merge(merge), data(n * 2, id) {}
  void update(int p, T val) {
    assert(0 <= p && p < n);
    p += n;
    data[p] = val;
    while (p /= 2) {
      int l = p * 2, r = p * 2 + 1;
      data[p] = merge(data[l], data[r]);
    }
  }
  T find(int l, int r) { return sub(l, r, 1, 0, n); }
};

int main() {
  int n, q, com, x, y;
  cin >> n >> q;
  SegmentTree<int> seg(n, 0x7FFFFFFF, [](int a, int b) { return min(a, b); });
  while (q--) {
    cin >> com >> x >> y;
    if (com)
      cout << seg.find(x, y + 1) << endl;
    else
      seg.update(x, y);
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb emplace_back

// 0-index 抽象化半開区間セグツリー verified AOJ DSL_2_AB
template <typename T, typename E> class segment_tree {
  typedef function<T(T, T)> F;
  typedef function<T(T, E)> G;

private:
  int num_of_elm_;
  vector<T> dat_;
  F f_;
  G g_;
  T ident_;

public:
  segment_tree(int n, F f, G g, T ident) : f_(f), g_(g), ident_(ident) {
    num_of_elm_ = 1;
    while (num_of_elm_ < n)
      num_of_elm_ *= 2;
    dat_.resize(2 * num_of_elm_, ident);
  }

  void update(int pos, T val) {
    int p = num_of_elm_ + pos;
    dat_[p] = g_(dat_[p], val);
    while (p != 1) {
      p /= 2;
      dat_[p] = f_(dat_[p * 2], dat_[p * 2 + 1]);
    }
  }

  T query(int L, int R, int l = 0, int r = 0, int k = 1) {
    if (k == 1)
      r = num_of_elm_;
    if (r <= L || R <= l)
      return ident_;
    else if (L <= l && r <= R) {
      return dat_[k];
    } else {
      return f_(query(L, R, l, (l + r) / 2, k * 2),
                query(L, R, (l + r) / 2, r, k * 2 + 1));
    }
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  auto f = [](int a, int b) { return min(a, b); };
  auto g = [](int a, int b) { return b; };
  segment_tree<int, int> st(n, f, g, (1LL << 31) - 1);

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


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb emplace_back

// 0-index 半開区間セグツリー(値の更新or加算 , 最小値or最大値or和) verified AOJ
// DSL_2_A
template <typename T, typename E> class segment_tree {
  typedef function<T(T, T)> F;
  typedef function<T(T, E)> G;

private:
  int num_of_elm_;
  vector<T> dat_;
  F f_;
  G g_;
  T ident_;

public:
  segment_tree(int n, F f, G g, T ident) : f_(f), g_(g), ident_(ident) {
    num_of_elm_ = 1;
    while (num_of_elm_ < n)
      num_of_elm_ *= 2;
    dat_.resize(2 * num_of_elm_, ident);
  }

  void update(int pos, T val) {
    int p = num_of_elm_ + pos;
    dat_[p] = g_(dat_[p], val);
    while (p != 1) {
      p /= 2;
      dat_[p] = f_(dat_[p * 2], dat_[p * 2 + 1]);
    }
  }

  T query(int L, int R, int l = 0, int r = 0, int k = 1) {
    if (k == 1)
      r = num_of_elm_;
    if (r <= L || R <= l)
      return ident_;
    else if (L <= l && r <= R) {
      return dat_[k];
    } else {
      return f_(query(L, R, l, (l + r) / 2, k * 2),
                query(L, R, (l + r) / 2, r, k * 2 + 1));
    }
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  auto f = [](int a, int b) { return a + b; };
  auto g = [](int a, int b) { return a + b; };
  segment_tree<int, int> st(n, f, g, 0);

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

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug " << x << endl;
#define inf 2147483647
#define B 400
using namespace std;

int find(int x, int y, vector<int> &a, vector<int> &b) {
  int ans = inf;
  int i = x;
  y++;
  while (i < y) {
    if (i % B == 0 && i + B <= y) {
      ans = min(ans, b[i / B]);
      i += B;
    } else {
      ans = min(ans, a[i]);
      i++;
    }
  }
  return ans;
}

void update(int n, int x, int y, vector<int> &a, vector<int> &b) {
  a[x] = y;
  b[x / B] = inf;
  for (int i = x - x % B; i < min(x - x % B + B, n); i++) {
    b[x / B] = min(b[x / B], a[i]);
  }
}

int main() {
  int n, q;
  while (cin >> n >> q) {
    vector<int> a(n, inf), b(B, inf);
    rep(i, q) {
      int com, x, y;
      cin >> com >> x >> y;
      if (com)
        cout << find(x, y, a, b) << endl;
      else
        update(n, x, y, a, b);
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug " << x << endl;
#define inf 2147483647
#define B 200
using namespace std;

int find(int x, int y, vector<int> a, vector<int> b) {
  int ans = inf;
  int i = x;
  y++;
  while (i < y) {
    if (i % B == 0 && i + B <= y) {
      ans = min(ans, b[i / B]);
      i += B;
    } else {
      ans = min(ans, a[i]);
      i++;
    }
  }
  return ans;
}

void update(int n, int x, int y, vector<int> &a, vector<int> &b) {
  a[x] = y;
  b[x / B] = inf;
  for (int i = x - x % B; i < min(x - x % B + B, n); i++) {
    b[x / B] = min(b[x / B], a[i]);
  }
}

int main() {
  int n, q;
  while (cin >> n >> q) {
    vector<int> a(n, inf), b(B);
    rep(i, q) {
      int com, x, y;
      cin >> com >> x >> y;
      if (com)
        cout << find(x, y, a, b) << endl;
      else
        update(n, x, y, a, b);
    }
  }
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int N, dat[300000];
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 main() {
  int n, q;
  cin >> n >> q;
  init(n);
  rep(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com)
      printf("%d\\n", query(x, y + 1, 0, 0, N));
    else
      update(x, y);
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int N, dat[200000];
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 main() {
  int n, q;
  cin >> n >> q;
  init(n);
  rep(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com)
      printf("%d\\n", query(x, y + 1, 0, 0, N));
    else
      update(x, y);
  }
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#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;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, cost;
};
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 2147483647;
const ll MOD = 1000000007LL;
const ll MAX = 200000;
ll n, dat[2 * MAX];
// 初期化
void init(ll n_) {
  n = 1;
  while (n < n_) {
    n *= 2;
  }
  for (ll i = 0; i < 2 * n - 1; i++) {
    dat[i] = INF;
  }
}
// k番目の値をaに変更
void update(ll k, ll 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]);
  }
}
//[a,b)の最小値を求める query(a,b,0,0,n)と呼ぶ
ll query(ll a, ll b, ll k, ll l, ll r) {
  if (r <= a || b <= l) {
    return INF;
  }
  if (a <= l && r <= b) {
    return dat[k];
  }
  ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
  ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
  return min(vl, vr);
}

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, cost;
};
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 2147483647;
const ll MOD = 1000000007LL;
const ll MAX = 100010;
ll n, dat[2 * MAX - 1];
// 初期化
void init(ll n_) {
  n = 1;
  while (n < n_) {
    n *= 2;
  }
  for (int i = 0; i < 2 * n - 1; i++) {
    dat[i] = INF;
  }
}
// k番目の値をaに変更
void update(int k, ll 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]);
  }
}
//[a,b)の最小値を求める query(a,b,0,0,n)と呼ぶ
ll query(ll a, ll b, ll k, ll l, ll r) {
  if (r <= a || b <= l) {
    return INF;
  }
  if (a <= l && r <= b) {
    return dat[k];
  }
  ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
  ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
  return min(vl, vr);
}

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, m, n) for (int i = m; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)
const int INF = 2147483647;
const double EPS = 1e-10;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;

const int MAX_N = 200010;

int N;
int dat[2 * MAX_N - 1];

//?????????
void init(int n_) {
  N = 1;
  while (N < n_)
    N *= 2;
  rep(i, 2 * N - 1) dat[i] = INF;
}

// k????????????(0-indexed)???a?????´??°
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]);
  }
}

//[a, b)???????°????????±???????
//??????k???[l, r)?????????
int query_(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 {
    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;
  init(n);
  int com, x, y;
  while (cin >> com >> x >> y) {
    if (com == 0)
      update(x, y);
    else
      cout << query(x, y + 1) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, m, n) for (int i = m; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)
const int INF = 2147483647;
const double EPS = 1e-10;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;

const int MAX_N = 100010;

int N;
int dat[2 * MAX_N - 1];

//?????????
void init(int n_) {
  N = 1;
  while (N < n_)
    N *= 2;
  rep(i, 2 * N - 1) dat[i] = INF;
}

// k????????????(0-indexed)???a?????´??°
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]);
  }
}

//[a, b)???????°????????±???????
//??????k???[l, r)?????????
int query_(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 {
    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;
  init(n);
  int com, x, y;
  rep(i, q) {
    cin >> com >> x >> y;
    if (com == 0)
      update(x, y);
    else
      cout << query(x, y + 1) << endl;
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#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;
}