alexjercan/bugnet huggingface dataset:
Problem p02345 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, q, c, x, y;
  scanf("%lld%lld", &n, &q);
  ll seg[n * 4], f = 1;
  while (f < n)
    f *= 2;
  for (i = 0; i < f * 2; ++i)
    seg[i] = 2147483647;
  for (i = 0; i < q; ++i) {
    scanf("%lld%lld%lld", &c, &x, &y);
    if (c) {
      ll ans = 2147483647;
      ll r = x + f;
      while (1) {
        ll las, ra = 1;
        while (!(r % 2))
          r /= 2;
        while (ra <= r)
          ra *= 2;
        ra /= 2;
        las = f / ra * (r + 1 - ra) - 1;
        // printf("f%lld r%lld ra%ld l%lld\\n", f, r, ra, l);
        while (las > y) {
          r *= 2;
          ra *= 2;
          las = f / ra * (r + 1 - ra) - 1;
          // printf("f%lld r%lld ra%ld l%lld\\n", f, r, ra, l);
        }
        if (ans > seg[r])
          ans = seg[r];
        if (las == y)
          break;
        r++;
        // printf("f%lld r%lld ra%ld l%lld\\n", f, r, ra, l);
      }
      printf("%lld\\n", ans);
    } else {
      int now = (x + f) / 2;
      seg[x + f] = y;
      while (now) {
        seg[now] =
            seg[now * 2] > seg[now * 2 + 1] ? seg[now * 2 + 1] : seg[now * 2];
        now /= 2;
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, q, c, x, y;
  scanf("%lld%lld", &n, &q);
  ll seg[n * 4], f = 1;
  while (f < n)
    f *= 2;
  for (i = 0; i < f * 2; ++i)
    seg[i] = 2147483647;
  for (i = 0; i < q; ++i) {
    scanf("%lld%lld%lld", &c, &x, &y);
    if (c) {
      ll ans = 2147483647;
      ll r = x + f, l = y + f + 1;
      while (!(l % 2))
        l /= 2;
      l--;
      if (!y)
        l = 1;
      while (1) {
        ll las, ra = 1;
        while (!(r % 2))
          r /= 2;
        while (ra <= r)
          ra *= 2;
        ra /= 2;
        las = f / ra * (r + 1 - ra) - 1;
        // printf("f%lld r%lld ra%ld l%lld\\n", f, r, ra, l);
        while (las > y) {
          r *= 2;
          ra *= 2;
          las = f / ra * (r + 1 - ra) - 1;
          // printf("f%lld r%lld ra%ld l%lld\\n", f, r, ra, l);
        }
        if (ans > seg[r])
          ans = seg[r];
        if (l == r)
          break;
        r++;
        // printf("f%lld r%lld ra%ld l%lld\\n", f, r, ra, l);
      }
      printf("%lld\\n", ans);
    } else {
      int now = (x + f) / 2;
      seg[x + f] = y;
      while (now) {
        seg[now] =
            seg[now * 2] > seg[now * 2 + 1] ? seg[now * 2 + 1] : seg[now * 2];
        now /= 2;
      }
    }
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

const int maxN = 100001;

// 0:indexed
class RMQ {
private:
  int n;
  P dat[maxN * 4];

  //[a,b),[l,r) //(Max,Min)
  P rec(int a, int b, int k, int l, int r) {
    if (b <= l || r <= a)
      return P(-infi, infi);
    if (a <= l && r <= b)
      return P(dat[k].first, dat[k].second);
    else {
      P vl = rec(a, b, 2 * k + 1, l, (l + r) / 2),
        vr = rec(a, b, 2 * k + 2, (l + r) / 2, r);
      return P(std::max(vl.first, vr.first), std::min(vl.second, vr.second));
    }
  }

public:
  void init(int x) {
    n = 1;
    while (n < x)
      n *= 2;
    rep(i, 2 * n - 1) dat[i] = P(-infi, infi);
  }

  void update(int k, int a) {
    k += n - 1;
    dat[k] = P(a, a);
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k].first = std::max(dat[2 * k + 1].first, dat[2 * k + 2].first);
      dat[k].second = std::min(dat[2 * k + 1].second, dat[2 * k + 2].second);
    }
  }

  //[a,b] //(Max,Min)
  P query(int a, int b) { return rec(a, b + 1, 0, 0, n); }
};

int n, q;
RMQ r;

int main() {
  std::cin >> n >> q;
  r.init(n);
  rep(i, q) {
    int a, b, c;
    std::cin >> a >> b >> c;
    if (a == 0)
      r.update(b, c);
    else {
      int ans = r.query(b, c).second;
      std::cout << (ans == infi ? 2147483647 : ans) << std::endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cstdio>
#include <iostream>

int data[100001];

int find(int s, int t) { return *std::min_element(data + s, data + t + 1); }

void updata(int i, int x) { data[i] = x; }

int main() {
  for (int i = 0; i < 100001; i++)
    data[i] = INT_MAX;

  int n, q, ch;
  ch = scanf("%d %d", &n, &q);

  for (int i = 0; i < q; i++) {
    int a, b, c;
    ch = scanf("%d %d %d", &a, &b, &c);

    if (a == 0)
      updata(b, c);
    else
      printf("%d\\n", find(b, c));
  }

  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <complex>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i, n) for (int i = 0; i < (n); i++)
#define ten(x) ((int)1e##x)

using namespace std;

int main() {
  int n;
  cin >> n;
  int q;
  cin >> q;
  vector<int> A(n, 2147483647);
  int interval = sqrt(n);
  vector<int> B(n / interval + 1, 2147483647);

  FOR(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      A[x] = y;
      int s = x / interval;
      int tmp = A[s * interval];
      // cout << "upd:" << x << " " << y << " " ;
      for (int j = s * interval; j < min((s + 1) * interval, n); j++)
        tmp = min(A[j], tmp);
      B[s] = tmp;
      // cout << s << " " << B[s] << endl;
    }
    if (com == 1) {
      int tmp = A[x];
      int j = x;
      // cout << "fin:"<< x << " " << y << endl;
      // FOR(ii,B.size()) cout << B[ii] << " ";
      // cout << endl;
      // FOR(ii,A.size()) cout << A[ii] << " ";
      // cout << endl;
      while (j <= y) {
        // cout << j << " ";
        if (j % interval == 0 && y - j >= interval - 1) {
          tmp = min(B[j / interval], tmp);
          j += interval;
        } else {
          tmp = min(A[j], tmp);
          j++;
        }
      }
      // cout << "ans:" << tmp << endl << endl;
      cout << tmp << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <complex>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i, n) for (int i = 0; i < (n); i++)
#define ten(x) ((int)1e##x)

using namespace std;

int main() {
  int n;
  cin >> n;
  int q;
  cin >> q;
  vector<int> A(n, 2147483647);
  FOR(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      A[x] = y;
    }
    if (com == 1) {
      int tmp = A[x];
      for (int i = x; i <= y; i++)
        tmp = min(tmp, A[i]);
      cout << tmp << endl;
    }
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const int MAX_N = 200001;
const int INF = 2147483647;

// 要素の数、区間などを何からの値を覚えておく配列
int n, q, v[2 * MAX_N - 1];

// 初期化
void init(int _n) {
  n = 1;
  while (n < _n)
    n *= 2;
  REP(i, 2 * n - 1) v[i] = INF;
}

// 添字が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[k * 2 + 1], v[k * 2 + 2]);
  }
}

// [a, b)の最小値を求める
// kは今見ている添字、l, rはそれに対応する[l, r)
// 呼び出す時はquery(a, b, 0, 0, n)として呼ぶ
int query(int a, int b, int k, int l, int r) {
  if (b <= l || a >= r)
    return INF;
  if (a <= l && b >= r)
    return v[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 >> n >> q;
  init(n);
  REP(i, q) {
    int Q, x, y;
    cin >> Q >> x >> y;
    if (Q)
      cout << query(x, y + 1, 0, 0, n) << endl;
    else
      update(x, y);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const int MAX_N = 100001;
const int INF = 2147483647;

// 要素の数、区間などを何からの値を覚えておく配列
int n, q, v[2 * MAX_N - 1];

// 初期化
void init(int _n) {
  n = 1;
  while (n < _n)
    n *= 2;
  REP(i, 2 * n - 1) v[i] = INF;
}

// 添字が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[k * 2 + 1], v[k * 2 + 2]);
  }
}

// [a, b)の最小値を求める
// kは今見ている添字、l, rはそれに対応する[l, r)
// 呼び出す時はquery(a, b, 0, 0, n)として呼ぶ
int query(int a, int b, int k, int l, int r) {
  if (b <= l || a >= r)
    return INF;
  if (a <= l && b >= r)
    return v[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 >> n >> q;
  init(n);
  REP(i, q) {
    int Q, x, y;
    cin >> Q >> x >> y;
    if (Q)
      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>
using namespace std;
int n, seg[1000001];
void update(int k, int x) {
  k += n - 1;
  seg[k] = x;
  while (k > 0) {
    k = (k - 1) / 2;
    seg[k] = min(seg[2 * k + 1], seg[2 * k + 2]);
  }
}
int find(int a, int b, int node, int l, int r) {
  if (a > r || b < l)
    return (INT_MAX);
  if (a <= l && r <= b)
    return (seg[node]);
  return (min(find(a, b, 2 * node + 1, l, (l + r) / 2),
              find(a, b, 2 * node + 2, (l + r) / 2 + 1, r)));
}
int main() {
  int q, com, x, y;
  cin >> n >> q;
  int a = 1;
  while (a < n)
    a *= 2;
  n = a;
  fill(seg, seg + 1000001, INT_MAX);
  for (int i = 0; i < q; i++) {
    cin >> com >> x >> y;
    if (com == 0)
      update(x, y);
    if (com == 1)
      cout << find(x, y, 0, 0, n - 1) << endl;
  }

  return (0);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, seg[200001];
void update(int k, int x) {
  k += n - 1;
  seg[k] = x;
  while (k > 0) {
    k = (k - 1) / 2;
    seg[k] = min(seg[2 * k + 1], seg[2 * k + 2]);
  }
}
int find(int a, int b, int node, int l, int r) {
  if (a > r || b < l)
    return (INT_MAX);
  if (a <= l && r <= b)
    return (seg[node]);
  return (min(find(a, b, 2 * node + 1, l, (l + r) / 2),
              find(a, b, 2 * node + 2, (l + r) / 2 + 1, r)));
}
int main() {
  int q, com, x, y;
  cin >> n >> q;
  int a = 1;
  while (a < n)
    a *= 2;
  n = a;
  fill(seg, seg + 100001, INT_MAX);
  for (int i = 0; i < q; i++) {
    cin >> com >> x >> y;
    if (com == 0)
      update(x, y);
    if (com == 1)
      cout << find(x, y, 0, 0, n - 1) << endl;
  }

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

#include <climits>
#include <iostream>

const int MAX = 1 << 19;

using namespace std;

int n;
int tree[MAX];

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

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

int query(int a, int b, int k, int l, int r) {
  if (b <= l || r <= a) {
    return INT_MAX;
  } else if (a <= l && r <= b) {
    return tree[k];
  } else {
    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 an, q, com, x, y;
  cin >> an >> q;
  init(an);
  while (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 <climits>
#include <iostream>

const int MAX = 1 << 17;

using namespace std;

int n;
int tree[MAX];

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

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

int query(int a, int b, int k, int l, int r) {
  if (b <= l || r <= a) {
    return INT_MAX;
  } else if (a <= l && r <= b) {
    return tree[k];
  } else {
    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 q, com, x, y;
  cin >> n >> q;
  init(n);
  while (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 <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
static const int INF = 2147483647;
static const int MAX_N = 1 << 18;

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] = 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() {
  int n_, q;
  scanf("%d %d", &n_, &q);
  init(n_);
  for (int i = 0; i < q; i++) {
    int com, x, y;
    scanf("%d %d %d", &com, &x, &y);
    if (com == 0)
      update(x, y);
    if (com == 1)
      printf("%d\\n", query(x, y + 1, 0, 0, n));
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
static const int INF = 2147483647;
static const int MAX_N = 100000;

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] = 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() {
  int n_, q;
  scanf("%d %d", &n_, &q);
  init(n_);
  for (int i = 0; i < q; i++) {
    int com, x, y;
    scanf("%d %d %d", &com, &x, &y);
    if (com == 0)
      update(x, y);
    if (com == 1)
      printf("%d\\n", query(x, y + 1, 0, 0, n));
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

class RangeMinQuery {
private:
  vector<int> value;
  int _size;

public:
  void Init(int size) {
    int bitcount = 0; //?????°
    int t = size;

    while (t != 0) {
      t /= 2;
      ++bitcount;
    }
    if (size % (1 << (bitcount - 1)) != 0)
      bitcount++;
    _size = (1 << bitcount) - 1;

    value.resize(_size);

    for (vector<int>::iterator it = value.begin(); it != value.end(); ++it) {
      (*it) = INF;
    }
  }

  void Update(int index, int v) {
    int n = index + (_size >> 1);
    value[n] = v;

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

  int _RunQuery(int s, int t, int k, int l, int r) {
    if (s <= l && r <= t) {
      return value[k];
    }
    if (r < s || t < l) {
      return INF;
    }
    return min(_RunQuery(s, t, 2 * k + 1, l, (l + r) / 2),
               _RunQuery(s, t, 2 * k + 2, (l + r) / 2 + 1, r));
  }

  int RunQuery(int s, int t) { return _RunQuery(s, t, 0, 0, (_size >> 1)); }
};

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

  cin >> n >> q;
  rmq.Init(n);

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

    if (com == 0)
      rmq.Update(x, y);
    else
      cout << rmq.RunQuery(x, y) << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int n, q, *a, i, j, com, x, y;

  cin >> n >> q;

  a = new int[n];
  for (i = n - 1; i >= 0; --i)
    a[i] = 2147483647;

  for (i = q; i > 0; --i) {
    cin >> com >> x >> y;

    if (!com) {
      a[x] = y;
    } else {
      cout << *min_element(a + x, a + y + 1) << endl;
    }
  }

  delete[] a;
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: 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);
    }
  }
}

Error: -11

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, 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;

class RMQ {
  static const int MAXN = 100000;
  static const int inf = INT_MAX;

private:
  int n;
  int dat[2 * MAXN - 1];

public:
  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] = inf;
    }
  }
  void update(int i, int x) {
    i += n - 1;
    dat[i] = x;
    while (i) {
      i = (i - 1) / 2;
      dat[i] = min(dat[2 * i + 1], dat[2 * i + 2]);
    }
  }
  int find(int s, int t, int k = 0, int l = 0, int r = -1) {
    if (r == -1) {
      r = n;
    }
    if (r <= s || t <= l) {
      return inf;
    }
    if (s <= l && r <= t) {
      return dat[k];
    } else {
      int m = (l + r) / 2;
      int vl = find(s, t, k * 2 + 1, l, m);
      int vr = find(s, t, k * 2 + 2, m, r);
      return min(vl, vr);
    }
  }
  // int find(int s,int t) {
  //  return find(s,t,0,0,n);
  //  }
};
int main() {
  int n, q;
  cin >> n >> q;
  RMQ rmq(n);
  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com) {
      printf("%d\\n", rmq.find(x, y + 1));
    } else {
      rmq.update(x, y);
    }
  }
  return 0;
}