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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for (auto it = li.begin(); it != li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];

  vector<bool> ac(n, true);
  int l = 0, r = 0, c = 0, d = 0;
  for (int i = 1; i <= n; i++) {
    l = r;
    for (; a[r] == i && r < n; r++)
      ;
    c = d;
    for (; b[d] == i && d < n; d++)
      ;
    if (l < r && c < d) {
      rep(i, (r - l) + (d - c) - 1) ac[(l - (d - 1) + i + n) % n] = false;
    }
  }

  int e = -1;
  rep(i, n) if (ac[i]) e = i;

  if (e == -1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    rep(i, n) cout << b[(-e + i + n) % n] << " ";
    cout << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for (auto it = li.begin(); it != li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];

  vector<bool> ac(n, true);
  int l = 0, r = 0, c = 0, d = 0;
  for (int i = 1; i <= n; i++) {
    l = r;
    for (; a[r] == i && r < n; r++)
      ;
    c = d;
    for (; b[d] == i && d < n; d++)
      ;
    if (l < r && c < d) {
      rep(i, (r - l) + (d - c) - 1) ac[(l - (d - 1) + 1 + i) % n] = false;
    }
  }

  int e = -1;
  rep(i, n) if (ac[i]) e = i;

  if (e == -1) {
    cout << "No" << endl;
    return 0;
  } else {
    cout << "Yes" << endl;
    rep(i, n) cout << b[(-e + i + n) % n] << " ";
    cout << endl;
  }
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int N;
vector<int> A, B;

void input(void) {
  cin >> N;
  A.resize(N);
  for (auto &ai : A)
    cin >> ai;
  B.resize(N);
  for (auto &bi : B)
    cin >> bi;
}

bool possible;
vector<int> res;

void solve(void) {
  map<int, int> cnt;
  for (auto ai : A)
    ++cnt[ai];
  for (auto bi : B)
    ++cnt[bi];
  possible = true;
  for (auto &e : cnt)
    possible &= e.second <= N;
  if (!possible)
    return;

  res.resize(N);
  for (int i = 0; i < N; ++i)
    res[i] = B[i];
  int idx;
  for (int i = 0; i < N; ++i) {
    if (i == 0 || A[i - 1] != A[i])
      idx = 0;
    if (A[i] != res[i])
      continue;
    for (; idx < N; ++idx) {
      if (A[i] != res[idx] && A[idx] != res[i]) {
        swap(res[i], res[idx]);
        break;
      }
    }
  }
  for (int i = 0; i < N; ++i)
    possible &= A[i] != res[i];
}

int main(void) {
  input();
  solve();
  if (possible) {
    cout << "Yes" << endl;
    for (auto resi : res)
      cout << resi << " ";
    cout << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int N;
vector<int> A, B;

void input(void) {
  cin >> N;
  A.resize(N);
  for (auto &ai : A)
    cin >> ai;
  B.resize(N);
  for (auto &bi : B)
    cin >> bi;
}

bool possible;
vector<int> res;

void solve(void) {
  map<int, int> cnt;
  for (auto ai : A)
    ++cnt[ai];
  for (auto bi : B)
    ++cnt[bi];
  possible = true;
  for (auto &e : cnt)
    possible &= e.second <= N;
  if (!possible)
    return;

  res.resize(N);
  for (int i = 0; i < N; ++i)
    res[i] = B[i];
  for (int i = 0; i < N; ++i) {
    if (A[i] != res[i])
      continue;
    for (int idx = 0; idx < N; ++idx) {
      if (A[i] != res[idx] && A[idx] != res[i]) {
        swap(res[i], res[idx]);
        break;
      }
    }
  }
  for (int i = 0; i < N; ++i)
    possible &= A[i] != res[i];
}

int main(void) {
  input();
  solve();
  if (possible) {
    cout << "Yes" << endl;
    for (auto resi : res)
      cout << resi << " ";
    cout << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p02559 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int nax = 5e5 + 5;
vector<long long> st(2 * nax);
int n;

void modify(int p, int v) {
  for (st[p += n] += v; p > 0; p >>= 1)
    st[p >> 1] = st[p] + st[p ^ 1];
}

long long sum(int l, int r) {
  l += n, r += n;
  long long ans = 0;
  while (l < r) {
    if (l & 1)
      ans += st[l++];
    if (r & 1)
      ans += st[--r];
    l >>= 1, r >>= 1;
  }
  return ans;
}

int main() {
  int q, a, b, t;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    st[i] = 0;
    cin >> st[i + n];
  }
  for (int i = n - 1; i > 0; i--)
    st[i] = st[2 * i] + st[2 * i + 1];
  while (q--) {
    cin >> t >> a >> b;
    if (!t) {
      modify(a, b);
    } else
      cout << sum(a, b) << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

const int nax = 5e5 + 5;
vector<long long> st(2 * nax);
int n;

void modify(int p, int v) {
  for (st[p += n] += v; p > 0; p--)
    st[p >> 1] = st[p] + st[p ^ 1];
}

long long sum(int l, int r) {
  l += n, r += n;
  long long ans = 0;
  while (l < r) {
    if (l & 1)
      ans += st[l++];
    if (r & 1)
      ans += st[--r];
    l >>= 1, r >>= 1;
  }
  return ans;
}

int main() {
  int q, a, b, t;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    st[i] = 0;
    cin >> st[i + n];
  }
  for (int i = n - 1; i > 0; i--)
    st[i] = st[2 * i] + st[2 * i + 1];
  while (q--) {
    cin >> t >> a >> b;
    if (!t) {
      modify(a, b);
    } else
      cout << sum(a, b) << endl;
  }
  return 0;
}
Problem p02559 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, q;
  cin >> n >> q;
  fenwick_tree<long long> f(n);
  for (int i = 0; i < n; ++i) {
    int el;
    cin >> el;
    f.add(i, el);
  }

  for (int i = 0; i < q; ++i) {
    int t, u, x;
    cin >> t >> u >> x;
    if (t == 0)
      f.add(u, x);
    else
      cout << f.sum(u, x) << "\\n";
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << "\\n" << (#x) << " = " << (x) << "\\n"
// #define int  long long int

void inputoutput() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

void dfs(int src, bool *vis, vector<int> v[]) {
  vis[src] = true;
  // cout<<src<<" ";

  for (auto it : v[src]) {
    if (!vis[it])
      dfs(it, vis, v);
  }
}

int32_t main() {
  inputoutput();

  long long int n, q;
  cin >> n >> q;
  long long int ar[n];
  for (long long int i = 0; i < n; ++i)
    cin >> ar[i];
  for (long long int i = 0; i < q; ++i) {
    long long int a, b, c;
    cin >> a >> b >> c;
    if (a == 0) {
      ar[b] = ar[b] + c;
    } else {
      long long int sum = 0;
      for (int i = b; i <= c - 1; ++i)
        sum += ar[i];
      cout << sum << "\\n";
    }
  }

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

#include <algorithm>
#include <atcoder/fenwicktree>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;
using namespace atcoder;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  fenwick_tree<ll> fw(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    fw.add(i, a);
  }
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 0) {
      int p, x;
      cin >> p >> x;
      fw.add(p, x);
    } else {
      int l, r;
      cin >> l >> r;
      cout << fw.sum(l, r) << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  ll a, b, c, sum = 0;
  cin >> n >> q;
  vector<ll> v(n);
  for (int i = 0; i < q; i++)
    cin >> v[i];
  for (int i = 0; i < q; i++) {
    cin >> a >> b >> c;
    if (a == 1) {
      for (int j = b; j < c; j++) {
        sum += v[j];
      }
      cout << sum << endl;
      sum = 0;
    } else {
      v[b] += c;
    }
  }
  return 0;
}
Problem p02559 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#define LIMIT1 200010
#define LIMIT2 500010
typedef long long ll;
typedef long double ld;
typedef const void cv;
// BIT start
const int MAX_N = LIMIT2;
ll bit[MAX_N + 1] = {0}, n;
// 1-indexed BIT
ll sum(int i) {
  ll s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & (-i);
  }
  return s;
}
void add(int i, ll x) {
  while (i <= n) {
    bit[i] += x;
    i += i & (-i);
  }
}
ll rangesum(int l, int r) { return sum(r) - sum(l - 1); }
// BIT end
int main() {
  ll i, q, x;
  cin >> n >> q;
  for (i = 1; i <= n; i++) {
    cin >> x;
    add(i, x);
  }
  int t, a, b;
  for (i = 1; i <= q; i++) {
    cin >> t >> a >> b;
    if (t == 0)
      add(a + 1, (ll)b);
    else
      cout << rangesum(a + 1, b) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
#define LIMIT1 200010
typedef long long ll;
typedef long double ld;
typedef const void cv;
// BIT start
const int MAX_N = LIMIT1;
int bit[MAX_N + 1] = {0}, n;
// 1-indexed BIT
ll sum(int i) {
  ll s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & (-i);
  }
  return s;
}
void add(int i, ll x) {
  while (i <= n) {
    bit[i] += x;
    i += i & (-i);
  }
}
ll rangesum(int l, int r) { return sum(r) - sum(l - 1); }
// BIT end
int main() {
  int q, x;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    add(i, x);
  }
  int t, a, b;
  for (int i = 1; i <= n; i++) {
    cin >> t >> a >> b;
    if (t == 0)
      add(a + 1, b);
    else
      cout << rangesum(a + 1, b) << endl;
  }
  return 0;
}
Problem p02559 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll, ll> prl;
typedef vector<ll> vcl;
typedef map<ll, ll> mapl;
typedef unordered_map<ll, ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define repi(i, a, b) for (int i = a; i <= b; i++)
#define repr(i, a, b) for (ll i = a; i >= b; i--)
#define reps(i, v) for (ll i = 0; i < v.size(); i++)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9 + 7;

// Binary_Indexed_Tree (Range_Sum_Query)
//(1-indexed)
const ll max_n = 1e6 + 5;
ll n, bit[max_n];
// i番目(1-indexed)までの和
ll sum(ll ii) {
  ll sm = 0;
  while (ii > 0) {
    sm += bit[ii];
    ii -= ii & -ii;
  }
  return sm;
}
// i番目(1-indexed)にxを加える
void add(ll ii, ll x) {
  while (ii <= n) {
    bit[ii] += x;
    ii += ii & -ii;
  }
}

int main() {
  // your code goes here
  ll q;
  cin >> n >> q;
  rep(i, 1, n) {
    ll x;
    cin >> x;
    add(i, x);
  }
  rep(i, 1, q) {
    ll a, b, c;
    cin >> a >> b >> c;
    if (a == 0)
      add(b + 1, c);
    else
      cout << sum(c) - sum(b) << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll, ll> prl;
typedef vector<ll> vcl;
typedef map<ll, ll> mapl;
typedef unordered_map<ll, ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define repi(i, a, b) for (int i = a; i <= b; i++)
#define repr(i, a, b) for (ll i = a; i >= b; i--)
#define reps(i, v) for (ll i = 0; i < v.size(); i++)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9 + 7;

// Binary_Indexed_Tree (Range_Sum_Query)
//(1-indexed)
const ll max_n = 1e6 + 5;
ll n, bit[max_n];
// i番目(1-indexed)までの和
ll sum(ll ii) {
  ll sm = 0;
  while (ii > 0) {
    sm += bit[ii];
    ii -= ii & -ii;
  }
  return sm;
}
// i番目(1-indexed)にxを加える
void add(ll ii, ll x) {
  while (ii <= n) {
    bit[ii] += x;
    ii += ii & -ii;
  }
}

int main() {
  // your code goes here
  ll n, q;
  cin >> n >> q;
  rep(i, 1, q) {
    ll a, b, c;
    cin >> a >> b >> c;
    if (a == 0)
      add(b + 1, c);
    else
      cout << sum(c) - sum(b) << endl;
  }
  return 0;
}
Problem p02559 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ar array
#define db double
#define filename "SUBKGCD"
#define pow pw
const db pi = 3.14159265358979323846;
int pw(int a, int b) {
  int ans = 1;
  while (b) {
    if (b % 2)
      ans *= a;
    a *= a;
    b /= 2;
  }
  return (ans);
}
const int mxn = 5e5 + 3;
int n, q;
int ft[2 * mxn];
void upd(int i, int v) {
  while (i <= n) {
    ft[i] += v;
    i += i & -i;
  }
}
int que(int i) {
  int res = 0;
  while (i >= 1) {
    res += ft[i];
    i -= i & -i;
  }
  return (res);
}
signed main() {
  // freopen(filename".inp","r",stdin);
  // freopen(filename".out","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    upd(i, x);
  }
  while (q--) {
    int qu, a, b;
    cin >> qu >> a >> b;
    if (qu == 0) {
      upd(a + 1, b);
    } else
      cout << que(b) - que(a) << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ar array
#define db double
#define filename "SUBKGCD"
#define pow pw
const db pi = 3.14159265358979323846;
int pw(int a, int b) {
  int ans = 1;
  while (b) {
    if (b % 2)
      ans *= a;
    a *= a;
    b /= 2;
  }
  return (ans);
}
const int mxn = 2e5 + 3;
int n, q;
int ft[2 * mxn];
void upd(int i, int v) {
  while (i <= n) {
    ft[i] += v;
    i += i & -i;
  }
}
int que(int i) {
  int res = 0;
  while (i >= 1) {
    res += ft[i];
    i -= i & -i;
  }
  return (res);
}
signed main() {
  // freopen(filename".inp","r",stdin);
  // freopen(filename".out","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    upd(i, x);
  }
  while (q--) {
    int qu, a, b;
    cin >> qu >> a >> b;
    if (qu == 0) {
      upd(a + 1, b);
    } else
      cout << que(b) - que(a) << "\\n";
  }
  return 0;
}
Problem p02559 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
long long N, Q;
long long trees[500005] = {0};

void update(int idx, long long value) {
  idx = idx + 1;
  while (idx <= N + 1) {
    trees[idx] += value;
    idx += idx & (-idx);
  }
}

long long getSum(int idx) {
  idx = idx + 1;
  long long s = 0;
  while (idx > 0) {
    s += trees[idx];
    idx -= idx & (-idx);
  }

  return s;
}

int main() {
  scanf("%lld%lld", &N, &Q);
  for (int i = 1; i <= N; ++i) {
    long long a;
    scanf("%lld", &a);
    update(i, a);
  }

  for (int i = 0; i < Q; ++i) {
    long long x1, x2, x3;
    scanf("%lld%lld%lld", &x1, &x2, &x3);
    if (x1 == 0) {
      update(x2 + 1, x3);
    } else {
      printf("%lld\\n", getSum(x3) - getSum(x2));
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
unsigned long long int *readStack(int length) {
  unsigned long long int *stack = new unsigned long long int[length];
  for (int i = 0; i < length; i++) {
    cin >> stack[i];
    // cout << stack[i] << " ";
  }
  // cout << endl;
  return stack;
}
unsigned long long int getSum(unsigned long long int tree[], int index) {
  unsigned long long int sum = 0;
  while (index > 0) {
    sum += tree[index];
    // cout << index << ' ';
    index -= index & (-index);
    // cout << index << endl;
  }
  return sum;
}
void updateTree(unsigned long long int *t, int index, int val, int l) {
  while (index <= l) { // Tree creation problems
    // if(tree[index] + s[i] > k)
    // return tree;
    t[index] += val;
    // cout << index << ' ';
    index += index & (-index);
    // cout << index << endl;
  }
}
unsigned long long int *getTree(unsigned long long int *s, int l) {
  unsigned long long int *tree = new unsigned long long int[l + 1];
  for (int i = 1; i <= l; i++)
    tree[i] = 0;
  for (int i = 0; i < l; i++) {
    updateTree(tree, i + 1, s[i], l);
  }
  // for (int i = 1; i <= l; i++)
  // cout << tree[i] << " ";
  // cout << endl;
  return tree;
}
int main() {
  unsigned int n, q;
  cin >> n >> q;
  unsigned long long int *a = getTree(readStack(n), n);
  unsigned long long int *ans = new unsigned long long int[n];
  unsigned int index = 0;
  for (int i = 0; i < q; i++) {
    int command;
    cin >> command;
    if (command == 1) {
      int l, r;
      cin >> l >> r;
      unsigned long long int sum = 0;
      if (l == 0)
        sum = getSum(a, r);
      else
        sum = getSum(a, r) - getSum(a, l);
      ans[index] = sum;
      index++;
    } else if (command == 0) {
      unsigned int p;
      unsigned long long int x;
      cin >> p >> x;
      updateTree(a, p + 1, x, n);
    }
  }
  for (int i = 0; i < index; i++)
    cout << ans[i] << endl;
}
Problem p02559 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

struct Lowmath {
  ll Sline;
  vector<ll> S;

  Lowmath(ll a) {
    Sline = a;
    S = vector<ll>(a + 1, 0);
  }
  void addset(ll a, ll b) {
    a += 1;
    do {
      S[a] += b;

    } while ((a += a & (-a)) <= Sline);
  }

  ll sumset0(ll i) {
    ll sum = 0;
    do {
      sum += S[i];
    } while (i -= i & (-i));
    return sum;
  }

  ll sumset(ll l, ll r) { return sumset0(r) - sumset0(l); }
};

string BN(ll a) {
  string S = "";
  S.push_back((a & 1) + '0');
  while (a >>= 1) {
    S.push_back((a & 1) + '0');
  }
  reverse(S.begin(), S.end());
  return S;
}

int main() {
  ll N, Q;
  cin >> N >> Q;
  Lowmath A(N);
  for (ll i = 0; i < A.Sline; i++) {
    ll s1;
    cin >> s1;
    A.addset(i, s1);
  }

  while (Q) {
    ll s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    if (s1 == 0)
      A.addset(s2, s3);
    else {
      cout << A.sumset(s2, s3) << endl;
    }

    Q--;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

struct Lowmath {
  ll Sline;
  vector<ll> S;
  vector<ll> SS;

  Lowmath(ll a) {
    Sline = a;
    S = vector<ll>(a);
    SS = vector<ll>(a + 1);
  }
  void AllSumSet() {
    SS[1] = S[0];
    for (ll i = 1; i < Sline; i++)
      SS[i + 1] = SS[i] + S[i];
  }

  void Lplus(ll a, ll b) {
    S[a] += b;
    for (ll i = a + 1; i < Sline + 1; i++)
      SS[i] += b;
  }

  ll Lsum(ll l, ll r) { return SS[r] - SS[l]; }
};

int main() {
  ll N, Q;
  cin >> N >> Q;
  Lowmath A(N);
  for (ll &i : A.S)
    cin >> i;
  A.AllSumSet();

  while (Q) {
    ll s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    if (s1 == 0)
      A.Lplus(s2, s3);
    else {
      cout << A.Lsum(s2, s3) << endl;
    }

    Q--;
  }
}
Problem p02559 (C++) — buggy submission, verdict: Runtime Error

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

template <class T> struct fenwick_tree {
  // using U = internal::to_unsigned_t<T>;
  using U = T;

public:
  fenwick_tree() : _n(0) {}
  fenwick_tree(int n) : _n(n), data(n) {}

  void add(int p, T x) {
    assert(0 <= p && p < _n);
    p++;
    while (p <= _n) {
      data[p - 1] += U(x);
      p += p & -p;
    }
  }

  T sum(int l, int r) {
    assert(0 <= l && l <= r && r <= _n);
    return sum(r) - sum(l);
  }

private:
  int _n;
  std::vector<U> data;

  U sum(int r) {
    U s = 0;
    while (r > 0) {
      s += data[r - 1];
      r -= r & -r;
    }
    return s;
  }
};

int main() {
  int N, Q, q, p, l, r;
  cin >> N >> Q;
  fenwick_tree<ll> ft(N);
  ll a, x;
  for (int i = 0; i < N; i++) {
    cin >> a;
    ft.add(i, a);
  }
  for (int i = 0; i < Q; i++) {
    cin >> q;
    if (q) {
      cin >> l >> r;
      cout << ft.sum(l, r) << "\\n";
    } else {
      cin >> p >> x;
      ft.add(p, x);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

template <class T> struct fenwick_tree {
  // using U = internal::to_unsigned_t<T>;
  using U = T;

public:
  fenwick_tree() : _n(0) {}
  fenwick_tree(int n) : _n(n), data(n) {}

  void add(int p, T x) {
    assert(0 <= p && p < _n);
    p++;
    while (p <= _n) {
      data[p - 1] += U(x);
      p += p & -p;
    }
  }

  T sum(int l, int r) {
    assert(0 <= l && l <= r && r <= _n);
    return sum(r) - sum(l);
  }

private:
  int _n;
  std::vector<U> data;

  U sum(int r) {
    U s = 0;
    while (r > 0) {
      s += data[r - 1];
      r -= r & -r;
    }
    return s;
  }
};

int main() {
  int N, Q, q, p, l, r;
  cin >> N >> Q;
  fenwick_tree<ll> ft(N);
  ll a, x;
  for (int i = 0; i < Q; i++) {
    cin >> a;
    ft.add(i, a);
  }
  for (int i = 0; i < Q; i++) {
    cin >> q;
    if (q) {
      cin >> l >> r;
      cout << ft.sum(l, r) << "\\n";
    } else {
      cin >> p >> x;
      ft.add(p, x);
    }
  }
  return 0;
}