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


Error: 0

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

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

void update(int i, int x, vector<int> &node, int n) {
  i += n - 1;
  node[i] = x;
  while (i > 0) {
    i = (i - 1) / 2;
    node[i] = min(node[2 * i + 1], node[2 * i + 2]);
  }
}
int find(int a, int b, int k, int l, int r, vector<int> &node) {
  if (r <= a || b <= l)
    return INT_MAX;
  if (a <= l && r <= b)
    return node[k];
  else {
    int vl = find(a, b, 2 * k + 1, l, (l + r) / 2, node);
    int vr = find(a, b, 2 * k + 2, (l + r) / 2, r, node);
    return min(vl, vr);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n_, q;
  cin >> n_ >> q;
  int n = 1;
  while (n < n_)
    n *= 2;
  vector<int> node(2 * n - 1, INT_MAX);

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

Error: TLE

Fixed submission:

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

void update(int i, int x, vector<int> &node, int n) {
  node[n - 1 + i] = x;
  for (int i = n - 2; i >= 0; i--) {
    node[i] = min(node[2 * i + 1], node[2 * i + 2]);
  }
}
int find(int x, int y, int k, int l, int r, vector<int> &node) {
  if (r <= x || y <= l)
    return INT_MAX;
  if (x <= l && r <= y)
    return node[k];

  int vl = find(x, y, 2 * k + 1, l, (l + r) / 2, node);
  int vr = find(x, y, 2 * k + 2, (l + r) / 2, r, node);
  return min(vl, vr);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n_, q;
  cin >> n_ >> q;
  int n = 1;
  while (n < n_)
    n *= 2;
  vector<int> node(2 * n - 1, INT_MAX);

  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      update(x, y, node, n);
    } else {
      if (x > y)
        swap(x, y);
      if (x == y) {
        cout << node[n - 1 + x] << endl;
        continue;
      }
      cout << find(x, y + 1, 0, 0, n, node) << endl;
    }
  }
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

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

#include <bits/stdc++.h>
#define _                                                                      \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

const int MAX_V = 1 << 20;

struct node {
  int first; // [0],1,2,3
  int mid;   // 0,1,[2],3
  int last;  // 0,1,2,[3]
  int min;
};

node nodes[MAX_V * 2];
int offset;

void update(int i, int x) {
  nodes[offset + i].min = x;
  if (offset + i == 0)
    return;
  int p = (offset + i - 1) / 2;
  while (true) {
    int minimum = min(nodes[p * 2 + 1].min, nodes[p * 2 + 2].min);
    if (nodes[p].min != minimum) {
      nodes[p].min = minimum;
      p = (p - 1) / 2;
    } else
      break;
  }
}
int find(int s, int t, int i) {
  if (nodes[i].first == s && nodes[i].last == t)
    return nodes[i].min;
  if (t < nodes[i].mid)
    return find(s, t, i * 2 + 1);
  if (s >= nodes[i].mid)
    return find(s, t, i * 2 + 2);
  return min(find(s, nodes[i].mid - 1, i * 2 + 1),
             find(nodes[i].mid, t, i * 2 + 2));
}

int main() {
  _;
  int n, q;
  cin >> n >> q;
  int a = 1;
  if (n > 1)
    for (; a < n; a *= 2) {
    }
  offset = a - 1;
  for (int i = 0; i < a; i++) {
    nodes[offset + i].first = nodes[offset + i].mid = nodes[offset + i].last =
        i;
    nodes[offset + i].min = 2147483647;
  }
  for (int i = offset - 1; i >= 0; i--) {
    nodes[i].first = nodes[2 * i + 1].first;
    nodes[i].mid = nodes[2 * i + 2].first;
    nodes[i].last = nodes[2 * i + 2].last;
    nodes[i].min = 2147483647;
  }
  REP(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      update(x, y);
    } else {
      cout << find(x, y, 0) << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define _                                                                      \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

const int MAX_V = 1000000;
int query[MAX_V];
int rangeMin[MAX_V];

int minOfRange(int s, int t) {
  if (t - s <= 1)
    return query[s];
  if (t - s == 2)
    return min(query[s], query[s + 1]);
  int med = (s + t) / 2;
  int left = minOfRange(s, med);
  int right = minOfRange(med, t);
  return min(left, right);
}

int main() {
  _;
  int n, q;
  cin >> n >> q;
  REP(i, n)
  query[i] = 2147483647;
  REP(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      query[x] = y;
    } else {
      cout << minOfRange(x, y + 1) << endl;
    }
  }
}
Problem p02345 (C++) — buggy submission, verdict: 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 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;
}

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

Error: -11

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

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

Error: 0

Fixed submission:

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

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

Error: 0

Fixed submission:

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

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

const int empty = 2147483647;

struct BigSegmentTree {
  typedef int T;
  T value;
  int lpos, rpos;
  BigSegmentTree *lch, *rch;

  BigSegmentTree(int n)
      : lpos(0), rpos(n), value(empty), lch(nullptr), rch(nullptr) {
    n = 1;
    while (n < rpos) {
      n *= 2;
    }
    rpos = n;
  }
  BigSegmentTree(int l, int r)
      : lpos(l), rpos(r), value(empty), lch(nullptr), rch(nullptr) {
    ;
  }

  T merge(T x, T y) { return (x < y ? x : y); }

  void update(int pos, T a) {
    if (rpos - lpos <= 1) {
      value = a;
      return;
    }
    int mid = (lpos + rpos) / 2;
    if (pos < mid) {
      if (!lch)
        lch = new BigSegmentTree(lpos, mid);
      lch->update(pos, a);
    } else {
      if (!rch)
        rch = new BigSegmentTree(mid, rpos);
      rch->update(pos, a);
    }
    T lv = lch ? lch->value : empty, rv = rch ? rch->value : empty;
    value = merge(lv, rv);
  }

  // merge([a, b))
  T query(int a, int b) {
    //    printf("[%d,%d), [%d,%d)\\n", a,b, lpos, rpos);
    if (rpos <= a || b <= lpos) {
      return empty;
    } else if (a <= lpos && rpos <= b) {
      return value;
    } else {
      T vl = lch ? lch->query(a, b) : empty;
      T vr = rch ? rch->query(a, b) : empty;
      return merge(vl, vr);
    }
  }
};

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

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

Error: TLE

Fixed submission:

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

const int empty = 2147483647;

struct BigSegmentTree {
  typedef int T;
  T value;
  int lpos, rpos;
  BigSegmentTree *lch, *rch;

  BigSegmentTree(int n) {
    int n_ = 1;
    while (n_ < n) {
      n *= 2;
    }
    lpos = 0, rpos = n_, value = empty;
    lch = rch = nullptr;
  }
  BigSegmentTree(int l, int r)
      : lpos(l), rpos(r), value(empty), lch(nullptr), rch(nullptr) {
    ;
  }

  T merge(T x, T y) { return (x < y ? x : y); }

  void update(int pos, T a) {
    if (rpos - lpos <= 1) {
      value = a;
      return;
    }
    int mid = (lpos + rpos) / 2;
    if (pos < mid) {
      if (!lch)
        lch = new BigSegmentTree(lpos, mid);
      lch->update(pos, a);
    } else {
      if (!rch)
        rch = new BigSegmentTree(mid, rpos);
      rch->update(pos, a);
    }
    T lv = lch ? lch->value : empty, rv = rch ? rch->value : empty;
    value = merge(lv, rv);
  }

  // merge([a, b))
  T query(int a, int b) {
    if (rpos <= a || b <= lpos) {
      return empty;
    } else if (a <= lpos && rpos <= b) {
      return value;
    } else {
      T vl = lch ? lch->query(a, b) : empty;
      T vr = rch ? rch->query(a, b) : empty;
      return merge(vl, vr);
    }
  }
};

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

  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      seg.update(x, y);
    } else {
      cout << seg.query(x, y + 1) << endl;
    }
  }
}
Problem p02345 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define ll long long
#define inf 999999999
#define con 131072
#define pa pair<int, int>

using namespace std;

int a[300000];

int minis(int i, int j) {
  if (i == j)
    return a[i];
  else if (i % 2 == 1)
    return min(a[i], minis(i + 1, j));
  else if (j % 2 == 0)
    return min(a[j], minis(i, j - 1));
  else
    return minis(i / 2, j / 2);
}

void upd(int x, int y) {
  a[x] = y;
  x = x / 2;
  while (x != 0) {
    a[x] = min(a[2 * x + 1], a[2 * x]);
    x = x / 2;
  }
}

int main() {
  int n, q, com, x, y;
  for (int i = 0; i < 270000; i++)
    a[i] = 2147483647;
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    cin >> com >> x >> y;
    if (com == 1)
      cout << minis(x + con, y + con) << endl;
    else
      upd(x + con, y);
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int a[100010];
  int n, q;
  cin >> n >> q;
  for (int u = 0; u < n; u++) {
    a[u] = 2147483647;
  }
  for (int z = 0; z < q; z++) {
    int c, x, y;
    cin >> c >> x >> y;
    if (c == 0) {
      a[x] = y;
    } else {
      int b[100010];
      for (int r = x; r <= y; r++) {
        b[r - x] = a[r];
      }
      sort(b, b + y - x + 1);
      cout << b[0] << endl;
    }
  }

  return 0;
}