alexjercan/bugnet huggingface dataset:
Problem p02345 (C++) — buggy submission, verdict: 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 = 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;
}

Error: 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 = 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;
}
Problem p02345 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using T = long long int;

class SegmentTree {
  vector<T> dat;
  int N;
  T E;
  function<T(T, T)> merge;
  T query_impl(int a, int b, int k, int l, int r) {
    if (a <= l && r <= b)
      return dat[k];
    if (r <= a || b <= l)
      return E;
    int mid = (l + r) / 2;
    T c1v = query_impl(a, b, k * 2 + 1, l, mid);
    T c2v = query_impl(a, b, k * 2 + 2, mid, r);
    return merge(c1v, c2v);
  }

public:
  SegmentTree(size_t N, function<T(T, T)> merge, T E) : E(E), merge(merge) {
    this->N = 1;
    while (this->N < N) {
      (this->N) *= 2;
    }
    dat.assign(this->N * 2 - 1, E);
  }
  void update(int pos, T val) {
    pos += N - 1;
    dat[pos] = val;
    while (pos != 0) {
      int par = (pos - 1) / 2;
      int c1 = par * 2 + 1;
      int c2 = par * 2 + 2;
      dat[par] = merge(dat[c1], dat[c2]);
      pos = par;
    }
  }
  T query(int a, int b) {
    assert(a <= b);
    return query_impl(a, b, 0, 0, N);
  }
};

T mymin(T a, T b) { return min(a, b); }
int main() {
  int n, q;
  cin >> n >> q;
  SegmentTree seg(n, mymin, int((1u << 31) - 1));
  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com) {
      if (x > y) {
        swap(x, y);
      }
      y++;
      cout << seg.query(x, y) << endl;
    } else {
      seg.update(x, y);
    }
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using T = long long int;

class SegmentTree {
  vector<T> dat;
  int N;
  T E;
  function<T(T, T)> merge;
  T query_impl(int a, int b, int k, int l, int r) {
    if (a <= l && r <= b)
      return dat[k];
    if (r <= a || b <= l)
      return E;
    int mid = (l + r) / 2;
    T c1v = query_impl(a, b, k * 2 + 1, l, mid);
    T c2v = query_impl(a, b, k * 2 + 2, mid, r);
    return merge(c1v, c2v);
  }

public:
  SegmentTree(size_t N, function<T(T, T)> merge, T E) : E(E), merge(merge) {
    while (this->N < N) {
      this->N *= 2;
    }
    dat.assign(this->N * 2 - 1, E);
  }
  void update(int pos, T val) {
    pos += N - 1;
    dat[pos] = val;
    while (pos != 0) {
      int par = (pos - 1) / 2;
      int c1 = par * 2 + 1;
      int c2 = par * 2 + 2;
      dat[par] = merge(dat[c1], dat[c2]);
      pos = par;
    }
  }
  T query(int a, int b) {
    assert(a <= b);
    return query_impl(a, b, 0, 0, N);
  }
};

T mymin(T a, T b) { return min(a, b); }
int main() {
  int n, q;
  cin >> n >> q;
  SegmentTree seg(n, mymin, int((1u << 31) - 1));
  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com) {
      if (x > y) {
        swap(x, y);
      }
      y++;
      cout << seg.query(x, y) << endl;
    } else {
      seg.update(x, y);
    }
  }

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

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

const int inf = 2147483647;
const int MAX = 2e5 + 10;

// RMQ
struct segtree {
  int N, dat[2 * MAX];
  segtree() {}
  segtree(int n) {
    N = 1;
    while (N < n)
      N *= 2;
    for (int i = 0; i < 2 * N - 1; i++)
      dat[i] = inf;
  }
  // update k th element
  void update(int k, int a) {
    k += N - 1; // leaf
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  // min [a, b)
  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 or b <= l)
      return inf;
    if (a <= l and r <= b)
      return dat[k];
    int m = (l + r) / 2;
    return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
  }
};

signed main() {
  int n, q;
  cin >> n >> q;
  segtree sg(n);
  rep(i, 0, q) {
    int c, x, y;
    cin >> c >> x >> y;
    if (c == 0) {
      sg.update(x, y);
    } else {
      cout << sg.query(x, y + 1) << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

const int inf = 2147483647;
const int MAX = 1e5 + 10;

// RMQ
struct segtree {
  int N, dat[2 * MAX];
  segtree() {}
  segtree(int n) {
    N = 1;
    while (N < n)
      N *= 2;
    for (int i = 0; i < 2 * N - 1; i++)
      dat[i] = inf;
  }
  // update k th element
  void update(int k, int a) {
    k += N - 1; // leaf
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  // min [a, b)
  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 or b <= l)
      return inf;
    if (a <= l and r <= b)
      return dat[k];
    int m = (l + r) / 2;
    return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
  }
};

signed main() {
  int n, q;
  cin >> n >> q;
  segtree sg(n);
  rep(i, 0, q) {
    int c, x, y;
    cin >> c >> x >> y;
    if (c == 0) {
      sg.update(x, y);
    } else {
      cout << sg.query(x, y + 1) << endl;
    }
  }
}
Problem p02345 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define INF 2147483647
vector<int> a(300000, INF);
int n, si;
void update(int, int);
int find(int, int, int, int, int);

int main() {
  int q, f;
  si = 1;
  cin >> n >> q;
  for (int i = 0;; i++) {
    si *= 2;
    if (si >= n)
      break;
  }

  for (int i = 0; i < q; i++) {
    cin >> f;
    if (f == 0) {
      int po, d;
      cin >> po >> d;
      update(po, d);
    } else {
      int st, go, mi;
      cin >> st >> go;
      mi = find(st, go + 1, 0, 0, si);
      cout << mi << endl;
    }
  }
  return 0;
}
void update(int p, int d) {
  int ko;
  ko = si - 1 + p;
  a[ko] = d;
  while (ko > 0) {
    ko = (ko - 1) / 2;
    a[ko] = min(a[ko * 2 + 1], a[ko * 2 + 2]);
  }
}
int find(int s, int t, int k, int l, int r) {
  int m = (l + r) / 2;
  if (s <= l && r <= t) {
    return a[k];
  } else if (r <= s || t <= l)
    return INF;

  return min(find(s, t, k * 2 + 1, l, m), find(s, t, k * 2 + 2, m, r));
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<pair<int, int>> a;
  pair<int, int> d;
  int n, q, f;
  cin >> n >> q;
  vector<int> m(n, 0);
  for (int i = 0; i < q; i++) {
    cin >> f;
    if (f == 0) {
      cin >> d.first >> d.second;
      m[d.first]++;
      a.push_back(d);
    } else {
      int st, go, ma = 2147483647;
      vector<int> m2(n, 0);
      cin >> st >> go;
      for (int j = 0; j != a.size(); j++) {
        if (a[j].first >= st && a[j].first <= go) {
          if (m[a[j].first] - 1 != m2[a[j].first]) {
            m2[a[j].first]++;
          } else
            ma = min(a[j].second, ma);
        }
      }
      cout << ma << endl;
    }
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = pow(2, 31) - 1;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  vi in(a, inf);
#define B 200
  vi t(a / B + 1, inf);
  while (in.size() % B)
    in.pb(inf);
  while (b--) {
    int c, d, e;
    cin >> c >> d >> e;
    if (c == 0) {
      in[d] = e;
      int q = d / B;
      t[q] = inf;
      rep(i, B) t[q] = min(t[q], in[q * B + i]);
    } else {
      int mi = inf;
      e++;
      while (d < e) {
        if (d % B == 0 && d + B <= e) {
          d += B - 1;
          mi = min(mi, t[d / B]);
        } else
          mi = min(mi, in[d]);
        d++;
      }
      cout << mi << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = pow(2, 31) - 1;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  vi in(a, inf);
#define B 200
  vi t(a / B + 1, inf);
  while (in.size() % B)
    in.pb(inf);
  while (b--) {
    int c, d, e;
    cin >> c >> d >> e;
    if (c == 0) {
      in[d] = e;
      int q = d / B;
      rep(i, B) t[q] = min(t[q], in[q * B + i]);
    } else {
      int mi = inf;
      e++;
      while (d < e) {
        if (d % B == 0 && d + B <= e) {
          d += B;
          mi = min(mi, t[d / B]);
        } else
          mi = min(mi, in[d]);
        d++;
      }
      cout << mi << endl;
    }
  }
}
Problem p02345 (C++) — buggy submission, verdict: 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(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;
}

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

#include <algorithm>
#include <iostream>
using namespace std;
int dp[270000], n, q, r, x, y, i;
int m(int l, int r, int k) {
  if (x <= l && r <= y)
    return dp[k];
  if (y <= l || r <= x)
    return 2147483647;
  return min(m(l, (l + r) / 2, k * 2 + 1), m((l + r) / 2, r, k * 2 + 2));
}
int main() {
  cin >> n >> q;
  r = 2;
  while (r < n)
    r *= 2;
  n = r, r *= 2;
  while (r--)
    dp[r] = 2147483647;
  while (q--) {
    cin >> r >> x >> y;
    if (r) {
      y++;
      cout << m(0, n, 0) << endl;
    } else {
      i = x + n - 1, dp[i] = y;
      while (i)
        i = (i - 1) / 2, dp[i] = min(dp[i * 2 + 1], dp[i * 2 + 2]);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int dp[200010], n, q, r, x, y, i;
int m(int l, int r, int k) {
  if (x <= l && r <= y)
    return dp[k];
  if (y <= l || r <= x)
    return 2147483647;
  return min(m(l, (l + r) / 2, k * 2 + 1), m((l + r) / 2, r, k * 2 + 2));
}
int main() {
  cin >> n >> q;
  r = 2;
  while (r < n)
    r *= 2;
  n = r, r *= 2;
  while (r--)
    dp[r] = 2147483647;
  while (q--) {
    cin >> r >> x >> y;
    if (r) {
      y++;
      cout << m(0, n, 0) << endl;
    } else {
      i = x + n - 1, dp[i] = y;
      while (i)
        i = (i - 1) / 2, dp[i] = min(dp[i * 2 + 1], dp[i * 2 + 2]);
    }
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define MAX_N 1 << 17
int n, dat[2 * (MAX_N)-1];

// INT＿MAXで初期化
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 = 0, int l = 0, int r = n) {
  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 q;
  cin >> n >> q;
  init(n);
  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com)
      cout << query(x, y + 1) << endl;
    else
      update(x, y);
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MAX_N 1 << 17
int n, dat[2 * MAX_N - 1];

// INT＿MAXで初期化
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 = 0, int l = 0, int r = n) {
  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 q;
  cin >> n >> q;
  init(n);
  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com)
      cout << query(x, y + 1) << endl;
    else
      update(x, y);
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <vector>
#define INF 2147483647
using namespace std;

class RMQ {
  int size;
  vector<int> minval;
  vector<int> maxval;
  pair<int, int> _query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return make_pair(INF, -INF);
    if (a <= l && r <= b)
      return make_pair(minval[k], maxval[k]);
    else {
      pair<int, int> vl = _query(a, b, k * 2 + 1, l, (l + r) / 2);
      pair<int, int> vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);
      return make_pair(min(vl.first, vr.first), max(vl.second, vr.second));
    }
  }

public:
  RMQ(int k) { init(k); }
  void init(int k) {
    for (size = 1; size < k;)
      size <<= 1;
    // size=1<<(32-__builtin_clz(k));
    minval = vector<int>(2 * size - 1, INF);
    maxval = vector<int>(2 * size - 1, -INF);
  }

  void update(int k, int t) {
    k += size - 1;
    minval[k] = maxval[k] = t;
    while (k > 0) {
      k = (k - 1) / 2;
      minval[k] = min(minval[k * 2 + 1], minval[k * 2 + 2]);
      maxval[k] = max(maxval[k * 2 + 1], maxval[k * 2 + 2]);
    }
  }

  pair<int, int> query(int a, int b) { return _query(a, b, 0, 0, size); }
};

int main() {
  int N, Q, c, x, y;
  scanf("%d%d", &N, &Q);
  RMQ rmq(N);
  for (; Q--;) {
    scanf("%d%d%d", &c, &x, &y);
    if (c) {
      pair<int, int> p = rmq.query(x, y + 1);
      printf("%d\\n", p.first);
    } else {
      rmq.update(x, y);
    }
  }
}

Error: TLE

Fixed submission:

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

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()

int *buildRMQ(int *a, int n) {
  int logn = 1;
  for (int k = 1; k < n; k *= 2)
    ++logn;
  int *r = new int[n * logn];
  int *b = r;
  copy(a, a + n, b);
  for (int k = 1; k < n; k *= 2) {
    copy(b, b + n, b + n);
    b += n;
    REP(i, n - k) b[i] = min(b[i], b[i + k]);
  }
  return r;
}
int minimum(int x, int y, int *rmq, int n) {
  int z = y - x, k = 0, e = 1, s; // y - x >= e = 2^k ???????????則 k
  s = ((z & 0xffff0000) != 0) << 4;
  z >>= s;
  e <<= s;
  k |= s;
  s = ((z & 0x0000ff00) != 0) << 3;
  z >>= s;
  e <<= s;
  k |= s;
  s = ((z & 0x000000f0) != 0) << 2;
  z >>= s;
  e <<= s;
  k |= s;
  s = ((z & 0x0000000c) != 0) << 1;
  z >>= s;
  e <<= s;
  k |= s;
  s = ((z & 0x00000002) != 0) << 0;
  z >>= s;
  e <<= s;
  k |= s;
  return min(rmq[x + n * k], rmq[y + n * k - e + 1]);
}

int a[100000], *p;
int main() {
  int n, q, c, x, y, f = 0;
  scanf("%d%d", &n, &q);
  for (y = 0; y < n; y++)
    a[y] = 0x7fffffff;
  for (; q--;) {
    scanf("%d%d%d", &c, &x, &y);
    if (c) {
      if (!f)
        p = buildRMQ(a, n), f = 1;
      printf("%d\\n", minimum(x, y, p, n));
    } else {
      if (f)
        delete[] p, f = 0;
      a[x] = y;
    }
  }
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
int n, q, data[300010];
int INF = (1LL << 31) - 1;

void init(int &n_) {
  int n = 1;
  while (n < n_)
    n *= 2;
  n_ = n;
  for (int i = 0; i < 2 * n - 1; i++)
    data[i] = INF;
}
void update(int k, int x) {
  k += n - 1;
  data[k] = x;
  while (k > 0) {
    k = (k - 1) / 2;
    data[k] = std::min(data[k * 2 + 1], data[k * 2 + 2]);
  }
}
int find(int a, int b, int k, int l, int r) {
  if (r <= a)
    return INF;
  if (b <= l)
    return INF;
  if (a <= l && r <= b)
    return data[k];
  int val1 = find(a, b, k * 2 + 1, l, (r + l) / 2);
  int val2 = find(a, b, k * 2 + 2, (r + l) / 2, r);
  return std::min(val1, val2);
}

int main() {
  std::cin >> n >> q;
  init(n);
  for (int i = 0; i < q; i++) {
    int a, b, c;
    std::cin >> a >> b >> c;
    if (a == 0)
      update(b, c);
    else
      std::cout << find(b, c + 1, 0, 0, n) << std::endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
int n, q, data[200010];
int INF = (1LL << 31) - 1;

void init(int &n_) {
  int n = 1;
  while (n < n_)
    n *= 2;
  n_ = n;
  for (int i = 0; i < 2 * n - 1; i++)
    data[i] = INF;
}
void update(int k, int x) {
  k += n - 1;
  data[k] = x;
  while (k > 0) {
    k = (k - 1) / 2;
    data[k] = std::min(data[k * 2 + 1], data[k * 2 + 2]);
  }
}
int find(int a, int b, int k, int l, int r) {
  if (r <= a)
    return INF;
  if (b <= l)
    return INF;
  if (a <= l && r <= b)
    return data[k];
  int val1 = find(a, b, k * 2 + 1, l, (r + l) / 2);
  int val2 = find(a, b, k * 2 + 2, (r + l) / 2, r);
  return std::min(val1, val2);
}

int main() {
  std::cin >> n >> q;
  init(n);
  for (int i = 0; i < q; i++) {
    int a, b, c;
    std::cin >> a >> b >> c;
    if (a == 0)
      update(b, c);
    else
      std::cout << find(b, c + 1, 0, 0, n) << std::endl;
  }
  return 0;
}