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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#define MAX_INT 2147483647
using namespace std;
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  vector<int> a(n + 1);
  for (int i = 0; i < n + 1; i++)
    a[i] = MAX_INT;
  for (int i = 0; i < q; i++) {
    int com, x, y;
    scanf("%d %d %d", &com, &x, &y);
    if (com) {
      int M = MAX_INT;
      for (int j = x; j <= y; j++)
        M = min(M, a[j]);
      printf("%d\\n", M);
    } else {
      a[x] = y;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#define MAX_INT 2147483647
using namespace std;
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  vector<int> a(n + 1);
  vector<int> flag;
  for (int i = 0; i < n + 1; i++)
    a[i] = MAX_INT;
  for (int i = 0; i < q; i++) {
    int com, x, y;
    scanf("%d %d %d", &com, &x, &y);
    if (com) {
      int M = MAX_INT;
      for (int j = 0; j < flag.size(); j++) {
        if (x <= flag[j] && flag[j] <= y) {
          M = min(M, a[flag[j]]);
        }
      }
      printf("%d\\n", M);
    } else {
      a[x] = y;
      flag.push_back(x);
    }
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <tuple>
#include <vector>
// #include "toollib.h"
#pragma warning(disable : 4018)
#define INT_MAX 2147483647
using namespace std;

int main() {
  vector<int> ret;
  int n, q;
  int find_x = -1, find_y = -1;
  cin >> n >> q;
  vector<int> a(n, INT_MAX);
  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0)
      a[x] = y;
    else {
      int m = INT_MAX;
      for (int i = x; i <= y; i++)
        m = min(m, a[i]);
      ret.push_back(m);
    }
  }
  for (int i = 0; i < ret.size(); i++) {
    cout << ret[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <tuple>
#include <vector>
// #include "toollib.h"
#pragma warning(disable : 4018)
#define INT_MAX 2147483647
using namespace std;

vector<int> ret;

void update(vector<int> *a, int x, int y) { (*a)[x] = y; }

void find(vector<int> a, int x, int y) {
  int m = INT_MAX;
  for (int i = x; i <= y; i++)
    m = min(m, a[i]);
  ret.push_back(m);
}

int main() {
  int n, q;
  int find_x = -1, find_y = -1;
  cin >> n >> q;
  vector<int> a(n, INT_MAX);
  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0)
      update(&a, x, y);
    else
      find(a, x, y);
  }
  for (int i = 0; i < ret.size(); i++) {
    cout << ret[i] << endl;
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

#define MAX_V (1 << 17)
#define INF INT_MAX

using namespace std;

int dat[MAX_V * 2], sz;

void update(int k, int x) {
  k += sz - 1;
  dat[k] = x;
  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(void) {

  fill(dat, dat + MAX_V * 2, INF);

  int n, q;
  cin >> n >> q;
  sz = 1;
  while (sz < n)
    sz *= 2;

  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com)
      cout << query(x, y + 1, 0, 0, sz) << endl;
    else
      update(x, y);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

#define MAX_V 100002
#define INF INT_MAX

using namespace std;

int dat[MAX_V * 2], sz;

void update(int k, int x) {
  k += sz - 1;
  dat[k] = x;
  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(void) {

  fill(dat, dat + MAX_V * 2, INF);

  int n, q;
  cin >> n >> q;
  sz = 1;
  while (sz < n)
    sz *= 2;

  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com)
      cout << query(x, y + 1, 0, 0, sz) << endl;
    else
      update(x, y);
  }

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

#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

#define max_n (1 << 18)

using namespace std;

int dat[max_n], n;

int get(int k) { return dat[k + n]; }

void update(int k, int a) {
  for (k += n, dat[k] = a; k > 1; k >>= 1)
    dat[k >> 1] = min(dat[k], dat[k ^ 1]);
}

int rmq(int a, int b) {
  int res = INT_MAX;
  for (a += n, b += n; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {
    if (a & 1)
      res = min(res, dat[a]);
    if ((b & 1) == 0)
      res = min(res, dat[b]);
  }
  return res;
}

int main(void) {

  fill(dat, dat + max_n, INT_MAX);
  int q;
  cin >> n >> q;

  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com)
      cout << rmq(x, y) << endl;
    else
      update(x, y);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

#define max_n (1 << 17)

using namespace std;

int dat[max_n], n;

int get(int k) { return dat[k + n]; }

void update(int k, int a) {
  for (k += n, dat[k] = a; k > 1; k >>= 1)
    dat[k >> 1] = min(dat[k], dat[k ^ 1]);
}

int rmq(int a, int b) {
  int res = INT_MAX;
  for (a += n, b += n; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {
    if (a & 1)
      res = min(res, dat[a]);
    if ((b & 1) == 0)
      res = min(res, dat[b]);
  }
  return res;
}

int main(void) {

  fill(dat, dat + max_n, INT_MAX);
  int q;
  cin >> n >> q;

  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com)
      cout << rmq(x, y) << endl;
    else
      update(x, y);
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdint.h>
#include <vector>

using namespace std;
const int INF = (1 << 31) - 1;
class segment_tree {
private:
  int n;
  vector<int> node;

public:
  // 元配列をセグメント木で表現する
  segment_tree(vector<int> v) {

    int sz = v.size();
    // 最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく
    n = 1;
    while (n < sz) {
      n *= 2;
    }
    node.resize(2 * n - 1, INF);
    // 最下段を初期化
    for (int i = 0; i < sz; i++) {
      node[i + n - 1] = v[i];
    }
    // 親の値を決めていく
    for (int i = n - 2; i >= 0; i--) {
      node[i] = min(node[2 * i + 1], node[2 * i + 2]);
    }
  }

  void update(int x, int val) {
    x += (n - 1);
    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = min(node[2 * x + 1], node[2 * x + 2]);
    }
  }
  //[a,b)の最小値を求める
  // k番目のノード　範囲は[l,r)
  int query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) {
      r = n;
    }
    if (r <= a || b <= l) {
      return INF;
    }
    if (a <= l && r <= b) {
      return node[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;
  int Q;
  cin >> N >> Q;
  segment_tree seg(vector<int>(N, INF));
  for (int i = 0; i < Q; i++) {
    int c, x, y;
    cin >> c >> x >> y;
    if (c == 0) {
      seg.update(x, y);
    } else {
      cout << seg.query(x, y + 1) << endl;
    }
  }
}


Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdint.h>
#include <vector>

using namespace std;
const int INF = (int)(pow(2, 31) - 1);
class segment_tree {
private:
  int n;
  vector<int> node;

public:
  // 元配列をセグメント木で表現する
  segment_tree(vector<int> v) {

    int sz = v.size();
    // 最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく
    n = 1;
    while (n < sz) {
      n *= 2;
    }
    node.resize(2 * n - 1, INF);
    // 最下段を初期化
    for (int i = 0; i < sz; i++) {
      node[i + n - 1] = v[i];
    }
    // 親の値を決めていく
    for (int i = n - 2; i >= 0; i++) {
      node[i] = min(node[2 * i + 1], node[2 * i + 2]);
    }
  }

  void update(int x, int val) {
    x += (n - 1);
    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = min(node[2 * x + 1], node[2 * x + 2]);
    }
  }
  //[a,b)の最小値を求める
  // k番目のノード　範囲は[l,r)
  int query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) {
      r = n;
    }
    if (r <= a || b <= l) {
      return INF;
    }
    if (a <= l && r <= b) {
      return node[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;
  int Q;
  cin >> N >> Q;
  segment_tree seg(vector<int>(N, INF));
  for (int i = 0; i < Q; i++) {
    int c, x, y;
    cin >> c >> x >> y;
    if (c == 0) {
      seg.update(x, y);
    } else {
      cout << seg.query(x, y + 1) << endl;
    }
  }
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

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

#include <array>
#include <fstream>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

enum command {
  com_update = 0, // update(i, x) : a_i???x????????´?????????
  com_find = 1 // find(s,t): a_s,a_{s+1},...,a_t???????°??????????????????????
};
const int INIT = 2147483647; // (1L << 31L) - 1L;
int main() {
  std::istream &c_in = cin;
  int n, q;
  c_in >> n >> q;
  array<int, 100000> A;
  A.fill(INIT);

  for (int j = 0; j < q; ++j) {
    int com, x, y;
    c_in >> com >> x >> y;
    if (com == com_update) {
      A[x] = y;
    } else if (com == com_find) {
      //
      int m = INIT;
      for (int i = x; i <= y; ++i) {
        if (A[i] < m) {
          m = A[i];
        }
      }
      cout << m << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <fstream>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

enum command {
  com_update = 0, // update(i, x) : a_i???x????????´?????????
  com_find = 1 // find(s,t): a_s,a_{s+1},...,a_t???????°??????????????????????
};
const int INIT = 2147483647; // (1L << 31L) - 1L;
int main() {
  std::istream &c_in = cin;
  int n, q;
  c_in >> n >> q;
  vector<int> A;
  A.resize(n);
  for (int i = 0; i < n; ++i) {
    A[i] = INIT;
  }

  for (int j = 0; j < q; ++j) {
    int com, x, y;
    c_in >> com >> x >> y;
    if (com == com_update) {
      A[x] = y;
    } else if (com == com_find) {
      //
      int m = INIT;
      for (int i = x; i <= y; ++i) {
        if (A[i] < m) {
          m = A[i];
        }
      }
      cout << m << endl;
    }
  }
}
Problem p02345 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <tuple>
#include <vector>
// #include "toollib.h"
#pragma warning(disable : 4018)
#define INT_MAX 2147483647
using namespace std;

int main() {
  vector<int> ret;
  int n, q;
  int find_x = -1, find_y = -1;
  cin >> n >> q;
  vector<int> a(n, INT_MAX);
  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0)
      a[x] = y;
    else {
      int m = INT_MAX;
      for (int i = x; i <= y; i++)
        m = min(m, a[i]);
      ret.push_back(m);
    }
  }
  for (int i = 0; i < ret.size(); i++) {
    cout << ret[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <tuple>
#include <vector>
// #include "toollib.h"
#pragma warning(disable : 4018)
#define INT_MAX 2147483647
using namespace std;

int main() {
  int n, q;
  int find_x = -1, find_y = -1;
  cin >> n >> q;
  vector<int> a(n, INT_MAX);
  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0)
      a[x] = y;
    else {
      int m = INT_MAX;
      for (int i = x; i <= y; i++)
        m = min(m, a[i]);
      cout << m << endl;
    }
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

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

int n, dat[10000000];

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

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

long long query(int a, int b, int k = 0, int l = 0, int r = n) {
  if (r <= a || b <= l)
    return (1LL << 31) - 1;

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

  long long vl = query(a, b, 2 * k + 1, l, (l + r) / 2),
            vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(vl, vr);
}

int main() {
  int q;
  cin >> n >> q;
  init(n);
  while (q--) {
    long long a, b, c;
    cin >> a >> b >> c;
    if (a) {
      cout << query(b, c + 1) << endl;
    } else {
      updata(b, c);
    }
  }
  return 0;
}


Error: 0

Fixed submission:

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

int n, dat[(1LL << 17) - 1];

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

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

long long query(int a, int b, int k = 0, int l = 0, int r = n) {
  if (r <= a || b <= l)
    return (1LL << 31) - 1;

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

  long long vl = query(a, b, 2 * k + 1, l, (l + r) / 2),
            vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(vl, vr);
}

int main() {
  int q;
  cin >> n >> q;
  init(n);
  while (q--) {
    long long a, b, c;
    cin >> a >> b >> c;
    if (a) {
      cout << query(b, c + 1) << endl;
    } else {
      updata(b, c);
    }
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

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

//@@@@@@@@@@@
//@ snippet SegTree
//@ alias   segtree
//@ options head
template <class Monoid> struct SegTree {
  using Func = function<Monoid(Monoid, Monoid)>;
  const int sz;
  const Func fn;
  const Monoid unity;
  vector<Monoid> dat;

  SegTree(int n, const Monoid &u, Func f)
      : sz(1 << (__lg(n + 5) + 1)), fn(f), unity(u), dat(sz * 2, unity) {}

  void set(int k, const Monoid &v) { dat[k + sz] = v; }

  Monoid &operator[](int k) { return dat[k + sz]; }

  void build() {
    for (int k = sz - 1; k > 0; --k)
      dat[k] = fn(dat[2 * k], dat[2 * k + 1]);
  }

  void update(int k, const Monoid &v) {
    dat[k += sz] = v;
    while (k >>= 1)
      dat[k] = fn(dat[2 * k], dat[2 * k + 1]);
  }

  Monoid query(int a, int b) const {
    Monoid L = unity, R = unity;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1)
        L = fn(L, dat[a++]);
      if (b & 1)
        R = fn(dat[--b], R);
    }
    return fn(L, R);
  }
};
//@@@@@@@@@

void AOJ_DSL_2_A() {
  int N, Q;
  int com, x, y;

  scanf("%d%d", &N, &Q);
  SegTree<int> seg(N, (1LL << 31) - 1, [](int a, int b) { return min(a, b); });

  while (Q--) {
    scanf("%d%d%d", &com, &x, &y);
    if (com == 0) {
      seg.update(x, y);
    } else {
      printf("%d\\n", seg.query(x, y + 1));
    }
  }

  return;
}

int main() {
  AOJ_DSL_2_A();
  return 0;
}


Error: 0

Fixed submission:

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

//@@@@@@@@@@@
//@ snippet SegTree
//@ alias   segtree
//@ options head
template <class Monoid> struct SegTree {
  using Func = function<Monoid(Monoid, Monoid)>;
  const int sz;
  const Func fn;
  const Monoid unity;
  vector<Monoid> dat;

  SegTree(int n, const Monoid &u, Func f)
      : sz(1 << __lg(n + 5)), fn(f), unity(u), dat(sz * 2, unity) {}

  void set(int k, const Monoid &v) { dat[k + sz] = v; }

  Monoid &operator[](int k) { return dat[k + sz]; }

  void build() {
    for (int k = sz - 1; k > 0; --k)
      dat[k] = fn(dat[2 * k], dat[2 * k + 1]);
  }

  void update(int k, const Monoid &v) {
    dat[k += sz] = v;
    while (k >>= 1)
      dat[k] = fn(dat[2 * k], dat[2 * k + 1]);
  }

  Monoid query(int a, int b) const {
    Monoid L = unity, R = unity;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1)
        L = fn(L, dat[a++]);
      if (b & 1)
        R = fn(dat[--b], R);
    }
    return fn(L, R);
  }
};
//@@@@@@@@@

void AOJ_DSL_2_A() {
  int N, Q;
  int com, x, y;

  scanf("%d%d", &N, &Q);
  SegTree<long long> seg(N, (1LL << 31) - 1,
                         [](long long a, long long b) { return min(a, b); });
  seg.build();

  while (Q--) {
    scanf("%d%d%d", &com, &x, &y);
    if (com == 0) {
      seg.update(x, y);
    } else {
      printf("%lld\\n", seg.query(x, y + 1));
    }
  }

  return;
}

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

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
using T = long long;

// RMQに答えるSegmentTree
// 必要に応じて書き換える．
const T INF = (1LL << 31) - 1LL;
struct SegmentTree {
private:
  int n;
  vector<T> node;

public:
  SegmentTree(vector<T> vect) {
    int sz = vect.size();
    n = 1;
    for (; n < sz;)
      n *= 2;
    node.resize(2 * n - 1, INF);

    for (int i = 0; i < sz; i++)
      node[i + n - 1] = vect[i];
    for (int i = n - 2; i >= 0; i--)
      node[i] = min(node[2 * i + 1], node[2 * i + 2]); // ここをうまく書き換える
  }

  void update(int x, T val) {
    x += (n - 1);

    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = min(node[2 * x + 1], node[2 * x + 2]);
    }
  }
  T getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0)
      r = n;
    if (r <= a || b <= l)
      return INF;
    if (a <= l && r <= b)
      return node[k];

    T vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
    T vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
};
int main() {
  int n, q;
  cin >> n >> q;
  vector<T> vect(n, INF);
  SegmentTree bit(vect);
  int c, x, y;

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

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
using T = long long;

// RMQに答えるSegmentTree
// 必要に応じて書き換える．
const T INF = (1LL << 31) - 1LL;
struct SegmentTree {
private:
  int n;
  vector<T> node;

public:
  SegmentTree(vector<T> vect) {
    int sz = vect.size();
    n = 1;
    for (; n < sz;)
      n *= 2;
    node.resize(2 * n - 1, INF);

    for (int i = 0; i < sz; i++)
      node[i + n - 1] = vect[i];
    for (int i = n - 2; i >= 0; i--)
      node[i] = min(node[2 * i + 1], node[2 * i + 2]); // ここをうまく書き換える
  }

  void update(int x, T val) {
    x += (n - 1);

    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = min(node[2 * x + 1], node[2 * x + 2]);
    }
  }
  int getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0)
      r = n;
    if (r <= a || b <= l)
      return INF;
    if (a <= l && r <= n)
      return node[k];

    int vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
    int vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
};
int main() {
  int n, q;
  cin >> n >> q;
  vector<T> vect(n, INF);
  SegmentTree bit(vect);
  int c, x, y;

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

  return 0;
}