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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define INF 100000005
#define MAX 131072
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int, int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int inf = 2147483647;

int n, dat[2 * MAX];
void init(int m) {
  n = 1;
  while (n < m)
    n *= 2;
  for (int i = 0; i < 2 * n; i++)
    dat[i] = inf;
}

void change(int x, int y) {
  x += n - 1;
  dat[x] = y;
  while (x > 0) {
    x = (x - 1) / 2;
    dat[x] = min(dat[x * 2 + 1], dat[x * 2 + 2]);
  }
}

int query(int a, int b, int k, int l, int r) {
  if (b <= l || r <= a)
    return inf;
  if (a <= l && r <= b)
    return dat[k];
  int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
  int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(vl, vr);
}

int main() {
  int m, q, c, x, y;
  scanf("%d%d", &m, &q);
  init(m);
  while (q--) {
    scanf("%d%d%d", &c, &x, &y);
    if (!c)
      change(x, y);
    else
      printf("%d\\n", query(x, y + 1, 0, 0, n));
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define INF 100000005
#define MAX 100001
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int, int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int inf = 2147483647;

int n, dat[2 * MAX];
void init(int m) {
  n = 1;
  while (n < m)
    n *= 2;
  for (int i = 0; i < 2 * n; i++)
    dat[i] = inf;
}

void change(int x, int y) {
  x += n - 1;
  dat[x] = y;
  while (x > 0) {
    x = (x - 1) / 2;
    dat[x] = min(dat[x * 2 + 1], dat[x * 2 + 2]);
  }
}

int query(int a, int b, int k, int l, int r) {
  if (b <= l || r <= a)
    return inf;
  if (a <= l && r <= b)
    return dat[k];
  int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
  int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(vl, vr);
}

int main() {
  int m, q, c, x, y, ans;
  scanf("%d%d", &m, &q);
  init(m);
  while (q--) {
    scanf("%d%d%d", &c, &x, &y);
    if (!c)
      change(x, y);
    else
      printf("%d\\n", query(x, y + 1, 0, 0, n));
  }
  return 0;
}
Problem p02345 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define INF 100000005
#define MAX 100001
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int, int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int inf = 2147483647;

int n, dat[10 * MAX];
void init(int m) {
  n = 1;
  while (n < m)
    n *= 2;
  for (int i = 0; i < 2 * n; i++)
    dat[i] = inf;
}

void change(int x, int y) {
  x += n - 1;
  dat[x] = y;
  while (x > 0) {
    x = (x - 1) / 2;
    dat[x] = min(dat[x * 2 + 1], dat[x * 2 + 2]);
  }
}

int query(int a, int b, int k, int l, int r) {
  if (b <= l || r <= a)
    return inf;
  if (a <= l && r <= b)
    return dat[k];
  int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
  int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(vl, vr);
}

int main() {
  int m, q, c, x, y, ans;
  scanf("%d%d", &m, &q);
  init(m);
  while (q--) {
    scanf("%d%d%d", &c, &x, &y);
    if (!c)
      change(x, y);
    else
      printf("%d\\n", query(x, y + 1, 0, 0, n));
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define INF 100000005
#define MAX 100001
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int, int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int inf = 2147483647;

int n, dat[2 * MAX];
void init(int m) {
  n = 1;
  while (n < m)
    n *= 2;
  for (int i = 0; i < 2 * n; i++)
    dat[i] = inf;
}

void change(int x, int y) {
  x += n - 1;
  dat[x] = y;
  while (x > 0) {
    x = (x - 1) / 2;
    dat[x] = min(dat[x * 2 + 1], dat[x * 2 + 2]);
  }
}

int query(int a, int b, int k, int l, int r) {
  if (b <= l || r <= a)
    return inf;
  if (a <= l && r <= b)
    return dat[k];
  int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
  int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(vl, vr);
}

int main() {
  int m, q, c, x, y, ans;
  scanf("%d%d", &m, &q);
  init(m);
  while (q--) {
    scanf("%d%d%d", &c, &x, &y);
    if (!c)
      change(x, y);
    else
      printf("%d\\n", query(x, y + 1, 0, 0, n));
  }
  return 0;
}
Problem p02346 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;
const LL mod = 1e9 + 7;
const LL LINF = 1LL << 62;

const int M_N = 100000;

LL bit[M_N + 1], n;

LL sum(int i) {
  LL s = 0;
  while (i > 0) {
    s += bit[i];
    i = i & (i - 1);
  }
  return s;
}

void add(int i, int x) {
  while (i <= n) {
    bit[i] += x;
    i += i & -i;
  }
}

int main() {
  int q;
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0)
      add(x, y);
    if (com == 1)
      cout << sum(y) - sum(x - 1) << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;
const LL mod = 1000000007;
const LL LINF = 1LL << 62;

const int M_N = 1 << 5;

LL bit[M_N + 1], n;

LL sum(int i) {
  int s = 0;
  while (i > 0) {
    s += bit[i];
    i = i & (i - 1);
  }
  return s;
}

void add(int i, int x) {
  while (i <= n) {
    bit[i] += x;
    i += i & -i;
  }
}

int main() {
  int q;
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0)
      add(x, y);
    if (com == 1)
      cout << sum(y) - sum(x - 1) << endl;
  }
  return 0;
}
Problem p02346 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

template <typename T> class SegmentTree {
  using func_t = function<T(T, T)>;
  const int n;
  const T id;
  func_t merge;
  vector<T> data;
  T sub(int l, int r, int node, int lb, int ub) {
    if (ub <= l || r <= lb)
      return id;
    if (l <= lb && ub <= r)
      return data[node];
    T vl = sub(l, r, node * 2 + 0, lb, (lb + ub) / 2);
    T vr = sub(l, r, node * 2 + 1, (lb + ub) / 2, ub);
    return merge(vl, vr);
  }
  int size(int n) {
    int res;
    for (res = 1; res < n; res <<= 1)
      ;
    return res;
  }

public:
  SegmentTree(int n, T id, func_t merge)
      : n(size(n)), id(id), merge(merge), data(size(n) * 2, id) {}
  void update(int p, T val) {
    assert(0 <= p && p < n);
    p += n;
    data[p] += val;
    while (p /= 2) {
      int l = p * 2, r = p * 2 + 1;
      data[p] = merge(data[l], data[r]);
    }
  }
  T find(int l, int r) { return sub(l, r, 1, 0, n); }
};

int main() {
  int n, q, com, x, y;
  cin >> n >> q;
  SegmentTree<int> seg(n, 0, [](int a, int b) { return a + b; });
  while (q--) {
    cin >> com >> x >> y;
    if (com)
      cout << seg.find(x - 1, y) << endl;
    else
      seg.update(x - 1, y);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

template <typename T> class SegmentTree {
  using func_t = function<T(T, T)>;
  const int n;
  const T id;
  func_t merge;
  vector<T> data;
  T sub(int l, int r, int node, int lb, int ub) {
    if (ub <= l || r <= lb)
      return id;
    if (l <= lb && ub <= r)
      return data[node];
    T vl = sub(l, r, node * 2 + 0, lb, (lb + ub) / 2);
    T vr = sub(l, r, node * 2 + 1, (lb + ub) / 2, ub);
    return merge(vl, vr);
  }
  int size(int n) { return n == 1 ? n : size((n + 1) / 2) * 2; }

public:
  SegmentTree(int n, T id, func_t merge)
      : n(size(n)), id(id), merge(merge), data(vector<T>(n * 2, id)) {}
  void update(int p, T val) {
    assert(0 <= p && p < n);
    p += n;
    data[p] += val;
    while (p /= 2) {
      int l = p * 2, r = p * 2 + 1;
      data[p] = merge(data[l], data[r]);
    }
  }
  T find(int l, int r) { return sub(l, r, 1, 0, n); }
};

int main() {
  long long int n, q, com, x, y;
  cin >> n >> q;
  SegmentTree<long long int> seg(
      n + 2, 0, [](long long int a, long long int b) { return a + b; });
  while (q--) {
    cin >> com >> x >> y;
    if (com)
      cout << seg.find(x - 1, y) << endl;
    else
      seg.update(x - 1, y);
  }
  return 0;
}
Problem p02346 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int n;
long long int dat[300000];

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

void add(int x, int i) {
  x += n - 1;
  dat[x] += i;
  while (x) {
    x = (x - 1) / 2;
    dat[x] = dat[x * 2 + 1] + dat[x * 2 + 2];
  }
}

long long int sum(int s, int t, int k, int l, int r) {
  if (t <= l || r <= s)
    return 0;
  if (s <= l && r <= t)
    return dat[k];
  return sum(s, t, k * 2 + 1, l, (l + r) / 2) +
         sum(s, t, k * 2 + 2, (l + r) / 2, r);
}

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int n;
long long int dat[300000];

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

void add(int x, int i) {
  x += n - 1;
  dat[x] += i;
  while (x) {
    x = (x - 1) / 2;
    dat[x] = dat[x * 2 + 1] + dat[x * 2 + 2];
  }
}

long long int sum(int s, int t, int k, int l, int r) {
  if (t <= l || r <= s)
    return 0;
  if (l == s && t == r)
    return dat[k];
  return sum(s, t, k * 2 + 1, l, (l + r) / 2) +
         sum(s, t, k * 2 + 2, (l + r) / 2, r);
}

int main() {
  int q;
  cin >> n >> q;
  init(n);
  for (int i = 0; i < q; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 0) {
      add(b - 1, c);
    } else {
      cout << sum(b - 1, c, 0, 0, n) << endl;
    }
  }
  return 0;
}
Problem p02346 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cctype>    // require tolower, toupper
#include <cfloat>
#include <climits>
#include <cmath>   // require fabs
#include <cstdio>  // require scanf printf
#include <cstdlib> // require abs exit atof atoi
#include <cstring> // require memset
#include <ctime>   // require srand
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int MAX_N = 100005;
int bit[MAX_N], n;

void add(int i, int x) {

  while (i <= n) {
    bit[i] += x;
    i += i & (-i);
  } // end while
}

int sum(int i) {

  int s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & (-i);
  } // end while

  return s;
}

void init_bit(void) {
  n = 0;
  memset(bit, 0, sizeof(bit));
}

int main() {
  init_bit();
  int q;
  scanf("%d %d", &n, &q);

  rep(i, q) {
    int com, x, y;
    scanf("%d %d %d", &com, &x, &y);
    if (com == 0) {
      add(x, y);
    } else {
      int s = sum(y);
      int t = sum(x - 1);
      int res = s - t;
      printf("%d\\n", res);
    } // end if
  }   // end rep

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cctype>    // require tolower, toupper
#include <cfloat>
#include <climits>
#include <cmath>   // require fabs
#include <cstdio>  // require scanf printf
#include <cstdlib> // require abs exit atof atoi
#include <cstring> // require memset
#include <ctime>   // require srand
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int MAX_N = 10005;
int bit[MAX_N], n;

void add(int i, int x) {

  while (i <= n) {
    bit[i] += x;
    i += i & (-i);
  } // end while
}

int sum(int i) {

  int s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & (-i);
  } // end while

  return s;
}

void init_bit(void) {
  n = 0;
  memset(bit, 0, sizeof(bit));
}

int main() {
  init_bit();
  int q;
  scanf("%d %d", &n, &q);

  rep(i, q) {
    int com, x, y;
    scanf("%d %d %d", &com, &x, &y);
    if (com == 0) {
      add(x, y);
    } else {
      int s = sum(y);
      int t = sum(x - 1);
      int res = s - t;
      printf("%d\\n", res);
    } // end if
  }   // end rep

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

#include <algorithm>
#include <iostream>
using namespace std;
#define N 131072
int tree[N * 2];
int getsum(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l)
    return 0;
  if (a <= l && r <= b)
    return tree[k];
  int m = (l + r) / 2;
  return getsum(a, b, k * 2 + 1, l, m) + getsum(a, b, k * 2 + 2, m, r);
}
void add(int a, int b) {
  a += N - 1;
  tree[a] += b;
  while (a) {
    a = (a - 1) / 2;
    tree[a] += b;
  }
}
int main() {
  int n, q;
  int c, a, b;
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    cin >> c >> a >> b;
    a--;
    if (c == 1)
      cout << getsum(a, b, 0, 0, N) << endl;
    else
      add(a, b);
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
#define N 131072
int tree[N * 2];
int getsum(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l)
    return 0;
  if (a <= l && r <= b)
    return tree[k];
  int m = (r) / 2;
  return getsum(a, b, k * 2 + 1, l, m) + getsum(a, b, k * 2 + 2, m, r);
}
void add(int a, int b) {
  a += N - 1;
  tree[a] += b;
  while (a) {
    a = (a - 1) / 2;
    tree[a] += b;
  }
}
int main() {
  int n, q;
  int c, a, b;
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    cin >> c >> a >> b;
    a--;
    if (c == 1)
      cout << getsum(a, b, 0, 0, N) << endl;
    else
      add(a, b);
  }
  return 0;
}
Problem p02346 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
#define pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
typedef long long ll;
typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7,
          around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
const ll LINF = 1e18;
const ld PI = abs(acos(-1));
const int sqrtN = 512;

struct SqrtDecomposition {
  vector<int> data;
  vector<int> bucketSum;
  int N, K;

  SqrtDecomposition(int n) : N(n) {
    K = (N + sqrtN - 1) / sqrtN;
    data.assign(K * sqrtN, 0);
    bucketSum.assign(K, 0);
  }

  void add(int k, int x) {
    data[k] += x;
    k = k / sqrtN;

    int sum = 0;
    for (int i = k * sqrtN; i < (k + 1) * sqrtN; i++) {
      sum += data[i];
    }

    bucketSum[k] = sum;
  }

  int get(int a, int b) {
    int sum = 0;
    for (int k = 0; k < K; k++) {
      int l = k * sqrtN, r = (k + 1) * sqrtN;

      if (b <= l || r <= a)
        continue;
      if (a <= l && r <= b)
        sum += bucketSum[k];
      else {
        for (int i = max(a, l); i < min(b, r); i++) {
          sum += data[i];
        }
      }
    }

    return sum;
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  SqrtDecomposition data(n);
  REP(i, 0, q) {
    int a, b, c;
    cin >> a >> b >> c;

    if (a == 0)
      data.add(b, c);
    else if (a == 1)
      cout << data.get(b, c + 1) << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
#define pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
typedef long long ll;
typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7,
          around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
const ll LINF = 1e18;
const ld PI = abs(acos(-1));
const int sqrtN = 512;

struct SqrtDecomposition {
  vector<int> data;
  vector<int> bucketSum;
  int N, K;

  SqrtDecomposition(int n) : N(n) {
    K = (N + sqrtN - 1) / sqrtN;
    data.assign(n, 0);
    bucketSum.assign(K, 0);
  }

  void add(int k, int x) {
    data[k] += x;
    k = k / sqrtN;

    int sum = 0;
    for (int i = k * sqrtN; i < (k + 1) * sqrtN; i++) {
      sum += data[i];
    }

    bucketSum[k] = sum;
  }

  int get(int a, int b) {
    int sum = 0;
    for (int k = 0; k < K; k++) {
      int l = k * sqrtN, r = (k + 1) * sqrtN;

      if (b <= l || r <= a)
        continue;
      if (a <= l && r <= b)
        sum += bucketSum[k];
      else {
        for (int i = max(a, l); i < min(b, r); i++) {
          sum += data[i];
        }
      }
    }

    return sum;
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  SqrtDecomposition data(n);
  REP(i, 0, q) {
    int a, b, c;
    cin >> a >> b >> c;

    if (a == 0)
      data.add(b, c);
    else if (a == 1)
      cout << data.get(b, c + 1) << endl;
  }

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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int seg[20000000];
int n, q;
void add(int a, int b) {
  a += n - 1;
  seg[a] += b;
  while (a > 0) {
    a = (a - 1) / 2;
    seg[a] += b;
  }
}
int sum(int a, int b, int l, int m, int k) {
  if (a <= l && m <= b)
    return seg[k];

  if (m < a || b < l)
    return 0;

  return sum(a, b, l, (l + m - 1) / 2, k * 2 + 1) +
         sum(a, b, (l + m + 1) / 2, m, k * 2 + 2);
}
int main(void) {
  cin >> n >> q;
  int n1 = 1;
  for (; n1 < n; n1 *= 2)
    ;
  n = n1;
  for (int i = 0; i < q; i++) {
    int c, x, y;
    cin >> c >> x >> y;
    x--;
    if (c == 0) {
      add(x, y);
    } else {
      y--;
      cout << sum(x, y, 0, n - 1, 0) << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int seg[200005];
int n, q;
void add(int a, int b) {
  a += n - 1;
  seg[a] += b;
  while (a > 0) {
    a = (a - 1) / 2;
    seg[a] += b;
  }
}
int sum(int a, int b, int l, int m, int k) {
  if (a <= l && m <= b)
    return seg[k];

  if (m < a || b < l)
    return 0;

  return sum(a, b, l, (l + m - 1) / 2, k * 2 + 1) +
         sum(a, b, (l + m + 1) / 2, m, k * 2 + 2);
}
int main(void) {
  cin >> n >> q;
  int n1 = 1;
  for (; n1 < n; n1 *= 2)
    ;
  n = n1;
  for (int i = 0; i < q; i++) {
    int c, x, y;
    cin >> c >> x >> y;
    x--;
    if (c == 0) {
      add(x, y);
    } else {
      y--;
      cout << sum(x, y, 0, n - 1, 0) << endl;
    }
  }
}
Problem p02346 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int n, q, bit[10000001];
void add(int a, int b) {
  bit[a] += b;
  while (a <= n) {
    a += a & -a;
    bit[a] += b;
  }
}
int sum(int i) {
  if (i == 0)
    return 0;

  return bit[i] + sum(i - (i & -i));
}
int main(void) {
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    int c, x, y;
    cin >> c >> x >> y;
    if (c == 0) {
      add(x, y);
    } else {
      cout << sum(y) - sum(x - 1) << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int n, q, bit[100001];
void add(int a, int b) {
  bit[a] += b;
  while (a <= n) {
    a += a & -a;
    bit[a] += b;
  }
}
int sum(int i) {
  if (i == 0)
    return 0;

  return bit[i] + sum(i - (i & -i));
}
int main(void) {
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    int c, x, y;
    cin >> c >> x >> y;
    if (c == 0) {
      add(x, y);
    } else {
      cout << sum(y) - sum(x - 1) << endl;
    }
  }
}
Problem p02346 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define MAX 300000
using namespace std;
int D[MAX];
int n = 1;

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

void add(int k, int a) {
  k += n - 1;
  D[k] += a;

  while (k > 0) {
    k = (k - 1) / 2;
    D[k] = D[2 * k + 1] + D[2 * k + 2];
  }
}

int query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l)
    return 0;
  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 vleft + vright;
}

int getSum(int a, int b) { return query(a, b, 0, 0, n); }

int main() {
  int q, com, x, y, n_, min;
  cin >> n_ >> q;
  initRSQ(n_);
  for (int i = 0; i < q; i++) {
    cin >> com >> x >> y;
    x--;
    if (com == 0)
      add(x, y);
    else
      cout << getSum(x, y) << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#define MAX 250000
using namespace std;
int D[MAX];
int n = 1;

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

void add(int k, int a) {
  k += n - 1;
  D[k] += a;

  while (k > 0) {
    k = (k - 1) / 2;
    D[k] = D[2 * k + 1] + D[2 * k + 2];
  }
}

int query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l)
    return 0;
  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 vleft + vright;
}

int getSum(int a, int b) { return query(a, b, 0, 0, n); }

int main() {
  int q, com, x, y, n_, min;
  cin >> n_ >> q;
  initRSQ(n_);
  for (int i = 0; i < q; i++) {
    cin >> com >> x >> y;
    x--;
    if (com == 0)
      add(x, y);
    else
      cout << getSum(x, y) << endl;
  }
  return 0;
}