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

// #define LOCAL

#include <algorithm>
#include <assert.h>
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

// #define int long long
typedef long long ll;

const ll INF = 1e18;

using namespace std;

const int MAX_N = 300100;
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] = 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);
  }
}

signed main() {
#ifdef LOCAL
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif

  int N, Q;
  int com, x, y;

  cin >> N >> Q;
  init(N + 100);
  REP(i, Q) {
    cin >> com >> x >> y;
    if (com == 0) {
      update(x, y);
    } else {
      cout << query(x, y + 1, 0, 0, n) << endl;
    }
  }
}

Error: 0

Fixed submission:

// #define LOCAL

#include <algorithm>
#include <assert.h>
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

// #define int long long
typedef long long ll;

const ll INF = 1e18;

using namespace std;

const int MAX_N = 130100;
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] = 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);
  }
}

signed main() {
#ifdef LOCAL
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif

  int N, Q;
  int com, x, y;

  cin >> N >> Q;
  init(N + 100);
  REP(i, Q) {
    cin >> com >> x >> y;
    if (com == 0) {
      update(x, y);
    } else {
      cout << query(x, y + 1, 0, 0, n) << endl;
    }
  }
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <climits>
#include <cstdio>
#include <iostream>
#define MAX 300000
#define INF INT_MAX
using namespace std;

int D[MAX];
int n = 1;
int inf;

void initRMQ(int n_) {
  while (n < n_)
    n *= 2;
  for (int i = 0; i < 2 * n - 1; i++) {
    D[i] = INF;
  }
}

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 D[k];

  int vleft, vright;
  vleft = query(a, b, 2 * k + 1, l, (l + r) / 2);
  vright = query(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(vleft, vright);
}

int findMin(int a, int b) { return query(a, b + 1, 0, 0, n); }

void update(int k, int a) {
  k += n - 1;
  D[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    D[k] = min(D[2 * k + 1], D[2 * k + 2]);
  }
}

int main() {
  int q, com, x, y, n_, min;
  cin >> n_ >> q;
  initRMQ(n_);
  for (int i = 0; i < q; i++) {
    cin >> com >> x >> y;
    if (com == 0)
      update(x, y);
    else
      cout << findMin(x, y) << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <climits>
#include <cstdio>
#include <iostream>
#define MAX 200000
#define INF INT_MAX
using namespace std;

int D[MAX];
int n = 1;
int inf;

void initRMQ(int n_) {
  while (n < n_)
    n *= 2;
  for (int i = 0; i < 2 * n - 1; i++) {
    D[i] = INF;
  }
}

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 D[k];

  int vleft, vright;
  vleft = query(a, b, 2 * k + 1, l, (l + r) / 2);
  vright = query(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(vleft, vright);
}

int findMin(int a, int b) { return query(a, b + 1, 0, 0, n); }

void update(int k, int a) {
  k += n - 1;
  D[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    D[k] = min(D[2 * k + 1], D[2 * k + 2]);
  }
}

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

#include <iostream>
using namespace std;
#define INF 2147483647
int n, q, rmq[262144];
void update(int a, int b) {
  a += n - 1;
  rmq[a] = b;
  while (a > 0) {
    a = (a - 1) / 2;
    rmq[a] = min(rmq[2 * a + 1], rmq[2 * a + 2]);
  }
}
int query(int a, int b, int k, int s, int t) {
  if (a <= s && t <= b)
    return rmq[k];
  if (t < a || b < s)
    return INF;

  return min(query(a, b, k * 2 + 1, s, (t + s - 1) / 2),
             query(a, b, k * 2 + 2, (t + s + 1) / 2, t));
}
int main(void) {
  int n1;
  cin >> n1 >> q;

  for (n = 1; n < n1; n *= 2)
    ;
  for (int i = 0; i < n * 2 - 1; i++)
    rmq[i] = INF;

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

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
#define INF 2147483647
int n, q, rmq[200000];
void update(int a, int b) {
  a += n - 1;
  rmq[a] = b;
  while (a > 0) {
    a = (a - 1) / 2;
    rmq[a] = min(rmq[2 * a + 1], rmq[2 * a + 2]);
  }
}
int query(int a, int b, int k, int s, int t) {
  if (a <= s && t <= b)
    return rmq[k];
  if (t < a || b < s)
    return INF;

  return min(query(a, b, k * 2 + 1, s, (t + s - 1) / 2),
             query(a, b, k * 2 + 2, (t + s + 1) / 2, t));
}
int main(void) {
  int n1;
  cin >> n1 >> q;

  for (n = 1; n < n1; n *= 2)
    ;
  for (int i = 0; i < n * 2 - 1; i++)
    rmq[i] = INF;

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

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

long n, q;
long mn[300010];
long k = 0, v = 1;

void update(long i, long x) {
  i += v;
  // cout<<"v:"<<v<<endl;
  mn[i] = x;
  //  cout<<"mn["<<i<<"]:"<<mn[i]<<endl;
  i /= 2;
  while (i > 0) {
    int l = mn[i * 2];
    int r = mn[i * 2 + 1];
    mn[i] = min(l, r);
    //  cout<<"mn["<<i<<"]:"<<mn[i]<<endl;
    i /= 2;
  }
}

long find(long x, long y, long bottom = 0, long top = v, long node = 1) {
  //  cout<<"x:"<<x<<" y:"<<y<<" bottom:"<<bottom<<" top"<<top<<"
  //  node:"<<node<<endl;
  if (x <= bottom && top <= y)
    return mn[node];
  if (top <= x || y <= bottom)
    return INT_MAX;

  long mid = (bottom + top) / 2;
  long lmx = find(x, y, bottom, mid, node * 2);
  long rmx = find(x, y, mid, top, node * 2 + 1);
  return min(lmx, rmx);
}

int main() {
  cin >> n >> q;
  while (n >= v) {
    v *= 2;
    k += 1;
  }
  for (int i = 0; i < 300010; i++) {
    mn[i] = INT_MAX;
  }
  long com, x, y;
  for (int i = 0; i < q; i++) {
    cin >> com >> x >> y;
    if (com == 0) {
      update(x, y);
    } else if (com == 1) {
      cout << find(x, y + 1) << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

long n, q;
long mn[200010];
long k = 0, v = 1;

void update(long i, long x) {
  i += v;
  // cout<<"v:"<<v<<endl;
  mn[i] = x;
  //  cout<<"mn["<<i<<"]:"<<mn[i]<<endl;
  i /= 2;
  while (i > 0) {
    int l = mn[i * 2];
    int r = mn[i * 2 + 1];
    mn[i] = min(l, r);
    //  cout<<"mn["<<i<<"]:"<<mn[i]<<endl;
    i /= 2;
  }
}

long find(long x, long y, long bottom = 0, long top = v, long node = 1) {
  //  cout<<"x:"<<x<<" y:"<<y<<" bottom:"<<bottom<<" top"<<top<<"
  //  node:"<<node<<endl;
  if (x <= bottom && top <= y)
    return mn[node];
  if (top <= x || y <= bottom)
    return INT_MAX;

  long mid = (bottom + top) / 2;
  long lmx = find(x, y, bottom, mid, node * 2);
  long rmx = find(x, y, mid, top, node * 2 + 1);
  return min(lmx, rmx);
}

int main() {
  cin >> n >> q;
  while (n >= v) {
    v *= 2;
    k += 1;
  }
  for (int i = 0; i < 200010; i++) {
    mn[i] = INT_MAX;
  }
  long com, x, y;
  for (int i = 0; i < q; i++) {
    cin >> com >> x >> y;
    if (com == 0) {
      update(x, y);
    } else if (com == 1) {
      cout << find(x, y + 1) << endl;
    }
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define LL long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
using namespace std;
static const LL INF = 1LL << 61LL;
static const int MAX_N = 1 << 18;
typedef pair<int, int> PII;

int dat[MAX_N * 2];

class Segment {
public:
  int n;
  void inti(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    rep(i, n * 2 - 1) 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 (a <= l && r <= b)
      return dat[k];
    if (r <= a || b <= l)
      return INT_MAX;
    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() {
  Segment St;
  int N, Q;
  cin >> N >> Q;
  St.inti(N);
  rep(i, Q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (!com)
      St.update(x, y);
    else
      cout << St.query(x, y + 1, 0, 0, St.n) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define LL long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
using namespace std;
static const LL INF = 1LL << 61LL;
static const int MAX_N = 1e+5;
typedef pair<int, int> PII;

class Segment {
public:
  int n, dat[MAX_N];
  void inti(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    rep(i, n * 2 - 1) 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 (a <= l && r <= b)
      return dat[k];
    if (r <= a || b <= l)
      return INT_MAX;
    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() {
  Segment St;
  int N, Q;
  cin >> N >> Q;
  St.inti(N);
  rep(i, Q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (!com)
      St.update(x, y);
    else
      cout << St.query(x, y + 1, 0, 0, St.n) << endl;
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#define M ((1UL << 31) - 1)

int seg[600000];

int min(int x, int y) { return (x < y ? x : y); }

void init(void) {
  for (int i = 0; i < 600000; i++)
    seg[i] = M;
}

void update(int i) {
  seg[i] = min(seg[2 * i + 1], seg[2 * i + 2]);
  if (i)
    update((i - 1) / 2);
}

int find(int x, int y, int l, int r, int i) {
  if (r < x || y < l)
    return M;
  if (x <= l && r <= y)
    return seg[i];
  return min(find(x, y, l, (l + r) / 2, i * 2 + 1),
             find(x, y, (l + r) / 2 + 1, r, i * 2 + 2));
}

int main(void) {
  int n, q;
  scanf("%d%d", &n, &q);
  init();
  for (int i = 0; i < q; i++) {
    int c, x, y;
    scanf("%d%d%d", &c, &x, &y);
    if (c) {
      printf("%d\\n", find(x, y, 0, (1 << 18) - 1, 0));
    } else {
      seg[x + (1 << 18) - 1] = y;
      update((x + (1 << 18) - 1 - 1) / 2);
    }
  }
}

Error: 0

Fixed submission:

#include <cstdio>
#define M ((1UL << 31) - 1)

int seg[300000];

int min(int x, int y) { return (x < y ? x : y); }

void init(void) {
  for (int i = 0; i < 300000; i++)
    seg[i] = M;
}

void update(int i) {
  seg[i] = min(seg[2 * i + 1], seg[2 * i + 2]);
  if (i)
    update((i - 1) / 2);
}

int find(int x, int y, int l, int r, int i) {
  if (r < x || y < l)
    return M;
  if (x <= l && r <= y)
    return seg[i];
  return min(find(x, y, l, (l + r) / 2, i * 2 + 1),
             find(x, y, (l + r) / 2 + 1, r, i * 2 + 2));
}

int main(void) {
  int n, q;
  scanf("%d%d", &n, &q);
  init();
  for (int i = 0; i < q; i++) {
    int c, x, y;
    scanf("%d%d%d", &c, &x, &y);
    if (c) {
      printf("%d\\n", find(x, y, 0, (1 << 18) - 1, 0));
    } else {
      seg[x + (1 << 18) - 1] = y;
      update((x + (1 << 18) - 1 - 1) / 2);
    }
  }
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

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

const int N = 1 << 17;
const int INF = (1LL << 31LL) - 1;
int dat[2 * N - 1];
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) {
  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, (r + l) / 2);
    int vr = query(a, b, k * 2 + 2, (r + l) / 2, r);
    return min(vl, vr);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> q;
  init(n);

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

  return 0;
}

Error: 0

Fixed submission:

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

const int N = 100000;
const int INF = (1LL << 31LL) - 1;
int dat[2 * N - 1];
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) {
  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, (r + l) / 2);
    int vr = query(a, b, k * 2 + 2, (r + l) / 2, r);
    return min(vl, vr);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> q;
  init(n);

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

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

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100009;
int tree[3 * MAX_N];
int inv = INT_MAX;

int N, Q;

void init(int _N, int iniv) {
  for (N = 1; N <= _N;)
    N *= 2;
  for (int i = 0; i < 2 * N - 1; i++)
    tree[i] = iniv;
}

void update(int p, int a) {
  p += N - 1;
  tree[p] = a;
  for (; p > 0;) {
    p = (p - 1) / 2;
    tree[p] = min(tree[p * 2 + 1], tree[p * 2 + 2]);
  }
}

int query(int l, int r, int k, int nl, int nr) {
  if (nr <= l || r <= nl)
    return inv;
  if (l <= nl && nr <= r)
    return tree[k];

  int vl = query(l, r, k * 2 + 1, nl, (nl + nr) / 2);
  int vr = query(l, r, k * 2 + 2, (nl + nr) / 2, nr);
  return min(vl, vr);
}

int main() {
  scanf("%d%d", &N, &Q);
  init(N, inv);
  for (int i = 0; i < Q; i++) {
    int con, x, y;
    scanf("%d%d%d", &con, &x, &y);
    if (!con)
      update(x, y);
    else
      printf("%d\\n", query(x, y + 1, 0, 0, N));
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100009;
int tree[2 * MAX_N];
int inv = INT_MAX;

int N, Q;

void init(int _N, int iniv) {
  for (N = 1; N <= _N; N *= 2)
    ;
  for (int i = 0; i < 2 * N - 1; i++)
    tree[i] = iniv;
}

void update(int p, int a) {
  p += N - 1;
  tree[p] = a;
  for (; p > 0;) {
    p = (p - 1) / 2;
    tree[p] = min(tree[p * 2 + 1], tree[p * 2 + 2]);
  }
}

int query(int l, int r, int k, int nl, int nr) {
  if (nr <= l || r <= nl)
    return inv;
  if (l <= nl && nr <= r)
    return tree[k];

  int vl = query(l, r, k * 2 + 1, nl, (nl + nr) / 2);
  int vr = query(l, r, k * 2 + 2, (nl + nr) / 2, nr);
  return min(vl, vr);
}

int main() {
  scanf("%d%d", &N, &Q);
  init(N, inv);
  for (int i = 0; i < Q; i++) {
    int con, x, y;
    scanf("%d%d%d", &con, &x, &y);
    if (!con)
      update(x, y);
    else
      printf("%d\\n", query(x, y + 1, 0, 0, N));
  }
}
Problem p02345 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

#include <algorithm>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main() {
  ll n, q;
  cin >> n >> q;
  ll test = 1 << 31;

  ll a[n];
  REP(i, n) { a[i] = test * (-1) - 1; }
  ll com[q], x[q], y[q];
  REP(i, q) { cin >> com[i] >> x[i] >> y[i]; }
  REP(i, q) {
    if (com[i] == 0) {
      a[x[i]] = y[i];
    } else {
      ll c = a[x[i]];
      for (int j = x[i] + 1; j < y[i] + 1; j++) {
        c = min(c, a[j]);
      }
      cout << c << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>

#include <algorithm>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main() {
  ll n, q;
  cin >> n >> q;
  ll test = 1 << 31;

  ll a[n];
  REP(i, n) { a[i] = test * (-1) - 1; }
  ll com[q], x[q], y[q];
  REP(i, q) { cin >> com[i] >> x[i] >> y[i]; }
  REP(i, q) {
    vector<ll> b;
    if (com[i] == 0) {
      a[x[i]] = y[i];
    } else {
      for (int j = x[i]; j < y[i] + 1; j++) {
        b.pb(a[j]);
      }
      sort(b.begin(), b.end());
      cout << b[0] << endl;
      ;
    }
  }
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int A[(1 << 20)];
int n, Q;
int N;
void init() {
  N = 1;
  while (N < n)
    N *= 2;
  for (int i = 0; i < 2 * N - 1; i++)
    A[i] = 2147483647;
}
int find(int a, int b, int k, int l, int r) {
  if (a <= l && r <= b)
    return A[k];
  if (r <= a || b <= l)
    return 2147483647;
  int vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
  int vr = find(a, b, k * 2 + 2, (l + r) / 2, r);
  // printf("find %d %d %d %d\\n", l, r, vl,vr);
  return min(vl, vr);
}
void update(int i, int x) {
  i += N - 1;
  A[i] = x;
  // printf("update %d %d\\n", i, A[i]);
  while (i > 0) {
    i = (i - 1) / 2;
    A[i] = min(A[2 * i + 1], A[2 * i + 2]);
    // printf("update %d %d\\n", i, A[i]);
  }
}
int main() {
  cin >> n >> Q;
  init();
  for (int i = 0; i < Q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0)
      update(x, y);
    else
      printf("%d\\n", find(x, y + 1, 0, 0, N));
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int A[(1 << 17)];
int n, Q;
int N;
void init() {
  N = 1;
  while (N < n)
    N *= 2;
  for (int i = 0; i < 2 * N - 1; i++)
    A[i] = 2147483647;
}
int find(int a, int b, int k, int l, int r) {
  if (a <= l && r <= b)
    return A[k];
  if (r <= a || b <= l)
    return 2147483647;
  int vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
  int vr = find(a, b, k * 2 + 2, (l + r) / 2, r);
  // printf("find %d %d %d %d\\n", l, r, vl,vr);
  return min(vl, vr);
}
void update(int i, int x) {
  i += N - 1;
  A[i] = x;
  // printf("update %d %d\\n", i, A[i]);
  while (i > 0) {
    i = (i - 1) / 2;
    A[i] = min(A[2 * i + 1], A[2 * i + 2]);
    // printf("update %d %d\\n", i, A[i]);
  }
}
int main() {
  cin >> n >> Q;
  init();
  for (int i = 0; i < Q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0)
      update(x, y);
    else
      printf("%d\\n", find(x, y + 1, 0, 0, N));
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 7;
int minv[maxn];
void build(int k, int l, int r) {
  minv[k] = 2147483647;
  if (l == r)
    return;
  int m = (l + r) >> 1;
  build(k << 1, l, m);
  build(k << 1 | 1, m + 1, r);
  minv[k] = min(minv[k << 1], minv[k << 1 | 1]);
}
void update(int k, int l, int r, int p, int v) {
  if (l == r) {
    minv[k] = v;
    return;
  }
  int m = (l + r) >> 1;
  if (p <= m)
    update(k << 1, l, m, p, v);
  else
    update(k << 1 | 1, m + 1, r, p, v);
  minv[k] = min(minv[k << 1], minv[k << 1 | 1]);
}
int query(int k, int l, int r, int pl, int pr) {
  if (pl <= l && r <= pr)
    return minv[k];
  int m = (l + r) >> 1;
  int res = 2147483647;
  if (pl <= m)
    res = min(res, query(k << 1, l, m, pl, pr));
  if (pr > m)
    res = min(res, query(k << 1 | 1, m + 1, r, pl, pr));
  return res;
}
int main() {
  int n, q;
  cin >> n >> q;
  build(1, 1, n);
  while (q--) {
    int op, x, y;
    cin >> op >> x >> y;
    if (!op) {
      update(1, 1, n, ++x, y);
    } else {
      if (x > y)
        swap(x, y);
      printf("%d\\n", query(1, 1, n, ++x, ++y));
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
#define fs first
#define sc second
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
const ll N = 1e5 + 10, MX = (1LL << 31) - 1;
ll n, q, ar[N], sq, k;
ppi mn[N];
vector<ll> ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  cin >> n >> q;
  sq = ((ll)sqrt(n)), k = (n / sq);
  fill(ar, ar + N, MX);
  mn[0].fs.fs = 0;
  mn[0].fs.sc = sq - 1;
  mn[0].sc = MX;
  for (ll i = 1; i < sq; i++) {
    mn[i].fs.fs = k * i;
    mn[i].fs.sc = (k + 1) * i - 1;
    mn[i].sc = MX;
  }
  for (ll p = 0; p < q; p++) {
    ll a, b, c;
    cin >> a >> b >> c;
    if (!a) {
      ll mnn = 1e18 + 10;
      ar[b] = c;
      if (b % k == 0)
        for (ll i = b; i < b + k; i++)
          mnn = min(mnn, ar[i]);
      else if (b % k == k - 1)
        for (ll i = b - k + 1; i <= b; i++)
          mnn = min(mnn, ar[i]);
      else
        for (ll i = (b / k) * k; i < (b / k + 1) * k; i++)
          mnn = min(mnn, ar[i]);

      mn[b / k].sc = mnn;
    } else {
      ll mnn = 1e18 + 10;
      if ((b / k) == (c / k)) {
        for (int i = b; i <= c; i++)
          mnn = min(mnn, ar[i]);
        ans.PB(mnn);
        continue;
      }
      for (ll i = b; 1 < min(c + 1, (b / k + 1) * k); i++)
        mnn = min(mnn, ar[i]);
      for (ll i = c; i >= max(b - 1, (c / k) * k); i--)
        mnn = min(mnn, ar[i]);
      for (ll i = (b / k) + 1; i < (c / k); i++)
        mnn = min(mnn, mn[i].sc);
      ans.PB(mnn);
    }
  }
  for (ll i = 0; i < ans.size(); i++)
    cout << ans[i] << endl;
}