CPLibrary

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub o06660o/CPLibrary

:heavy_check_mark: test/ds/fw.test.cpp

Depends on

Code

// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/point_add_range_sum
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#include "../../src/ds/ft.hpp"
#include "../../src/misc/read.hpp"

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n = read(), q = read();
  FenwickTree<ll> fw(n);
  for (int i = 0; i < n; i++) {
    int a = read();
    fw.add(i, a);
  }
  while (q--) {
    int op = read();
    if (op == 0) {
      int p = read(), x = read();
      fw.add(p, x);
    } else {
      int l = read(), r = read();
      cout << fw.sum(l, r) << "\n";
    }
  }
  return 0;
}
#line 1 "test/ds/fw.test.cpp"
// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/point_add_range_sum
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#line 1 "src/ds/ft.hpp"
template <typename T>
struct FenwickTree {
  int n;
  vector<T> c;
  FenwickTree(int n) : n(n), c(n) {}
  void add(int pos, T x) {
    for (int i = pos + 1; i <= n; i += i & -i) c[i - 1] += x;
  }
  T pref(int r) const {
    T ret = 0;
    for (int i = r; i > 0; i -= i & -i) ret += c[i - 1];
    return ret;
  }
  T sum(int l, int r) const { return pref(r) - pref(l); }
};
#line 1 "src/misc/read.hpp"
#define GC ch = getchar_unlocked()
ll read() {
  ll x = 0, f = 1, GC;
  while (ch < '0' || ch > '9') ch == '-' ? f = -1, GC : GC;
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', GC;
  return x * f;
}
#undef GC
#line 8 "test/ds/fw.test.cpp"

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n = read(), q = read();
  FenwickTree<ll> fw(n);
  for (int i = 0; i < n; i++) {
    int a = read();
    fw.add(i, a);
  }
  while (q--) {
    int op = read();
    if (op == 0) {
      int p = read(), x = read();
      fw.add(p, x);
    } else {
      int l = read(), r = read();
      cout << fw.sum(l, r) << "\n";
    }
  }
  return 0;
}

Test cases

Env Name Status Elapsed Memory
g++ example_00 :heavy_check_mark: AC 5 ms 4 MB
g++ max_random_00 :heavy_check_mark: AC 62 ms 7 MB
g++ max_random_01 :heavy_check_mark: AC 70 ms 7 MB
g++ max_random_02 :heavy_check_mark: AC 66 ms 7 MB
g++ max_random_03 :heavy_check_mark: AC 69 ms 7 MB
g++ max_random_04 :heavy_check_mark: AC 68 ms 7 MB
g++ random_00 :heavy_check_mark: AC 53 ms 6 MB
g++ random_01 :heavy_check_mark: AC 56 ms 7 MB
g++ random_02 :heavy_check_mark: AC 39 ms 4 MB
g++ random_03 :heavy_check_mark: AC 19 ms 7 MB
g++ random_04 :heavy_check_mark: AC 21 ms 6 MB
g++ small_00 :heavy_check_mark: AC 5 ms 4 MB
g++ small_01 :heavy_check_mark: AC 4 ms 4 MB
g++ small_02 :heavy_check_mark: AC 4 ms 4 MB
g++ small_03 :heavy_check_mark: AC 4 ms 4 MB
g++ small_04 :heavy_check_mark: AC 4 ms 4 MB
g++ small_05 :heavy_check_mark: AC 4 ms 4 MB
g++ small_06 :heavy_check_mark: AC 4 ms 4 MB
g++ small_07 :heavy_check_mark: AC 4 ms 4 MB
g++ small_08 :heavy_check_mark: AC 4 ms 4 MB
g++ small_09 :heavy_check_mark: AC 4 ms 4 MB
Back to top page