This documentation is automatically generated by competitive-verifier/competitive-verifier
// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/point_add_range_sum
// competitive-verifier: TLE 0.5
// competitive-verifier: MLE 64
#include <iostream>
#include "src/DataStructure/BinaryIndexedTree.hpp"
using namespace std;
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
int N, Q;
cin >> N >> Q;
BinaryIndexedTree<long long> bit(N);
for (int i= 0; i < N; i++) {
long long a;
cin >> a;
bit.add(i, a);
}
while (Q--) {
int t, a, b;
cin >> t >> a >> b;
if (t) cout << bit.sum(a, b) << '\n';
else bit.add(a, b);
}
}
#line 1 "test/yosupo/point_add_range_sum.BIT.test.cpp"
// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/point_add_range_sum
// competitive-verifier: TLE 0.5
// competitive-verifier: MLE 64
#include <iostream>
#line 2 "src/DataStructure/BinaryIndexedTree.hpp"
#include <algorithm>
#include <vector>
template <typename T> class BinaryIndexedTree {
std::vector<T> dat;
public:
BinaryIndexedTree(int n): dat(n + 1, T()) {}
BinaryIndexedTree(int n, T a): BinaryIndexedTree(std::vector<T>(n, a)) {}
BinaryIndexedTree(const std::vector<T>& y): dat(y.size() + 1, 0) {
for (int i= y.size(); i--;) dat[i + 1]= y[i];
for (int i= 1, e= dat.size(), j; i < e; ++i)
if ((j= i + (i & -i)) < e) dat[j]+= dat[i];
}
void add(int i, T a= 1) {
for (++i; i < (int)dat.size(); i+= i & -i) dat[i]+= a;
}
T sum(int i) const { // sum [0,i)
T s= 0;
for (; i; i&= i - 1) s+= dat[i];
return s;
}
T sum(int l, int r) const { return sum(r) - sum(l); } // sum [l,r)
T operator[](int k) const { return sum(k + 1) - sum(k); }
int find(T k) const { // min { i : sum(i+1) > k } -> kth element(0-indexed)
int i= 0;
for (int p= 1 << (std::__lg(dat.size() - 1) + 1), e= dat.size(); p; p>>= 1)
if (i + p < e && dat[i + p] <= k) k-= dat[i+= p];
return i + 1 == (int)dat.size() ? -1 : i; // -1 -> no solutions
}
};
#line 6 "test/yosupo/point_add_range_sum.BIT.test.cpp"
using namespace std;
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
int N, Q;
cin >> N >> Q;
BinaryIndexedTree<long long> bit(N);
for (int i= 0; i < N; i++) {
long long a;
cin >> a;
bit.add(i, a);
}
while (Q--) {
int t, a, b;
cin >> t >> a >> b;
if (t) cout << bit.sum(a, b) << '\n';
else bit.add(a, b);
}
}
Env | Name | Status | Elapsed | Memory |
---|---|---|---|---|
g++-13 | example_00 |
![]() |
5 ms | 4 MB |
g++-13 | max_random_00 |
![]() |
149 ms | 7 MB |
g++-13 | max_random_01 |
![]() |
155 ms | 7 MB |
g++-13 | max_random_02 |
![]() |
149 ms | 7 MB |
g++-13 | max_random_03 |
![]() |
154 ms | 7 MB |
g++-13 | max_random_04 |
![]() |
155 ms | 7 MB |
g++-13 | random_00 |
![]() |
127 ms | 6 MB |
g++-13 | random_01 |
![]() |
127 ms | 7 MB |
g++-13 | random_02 |
![]() |
90 ms | 4 MB |
g++-13 | random_03 |
![]() |
42 ms | 7 MB |
g++-13 | random_04 |
![]() |
47 ms | 6 MB |
g++-13 | small_00 |
![]() |
6 ms | 4 MB |
g++-13 | small_01 |
![]() |
5 ms | 4 MB |
g++-13 | small_02 |
![]() |
5 ms | 4 MB |
g++-13 | small_03 |
![]() |
5 ms | 4 MB |
g++-13 | small_04 |
![]() |
5 ms | 4 MB |
g++-13 | small_05 |
![]() |
4 ms | 4 MB |
g++-13 | small_06 |
![]() |
5 ms | 4 MB |
g++-13 | small_07 |
![]() |
5 ms | 4 MB |
g++-13 | small_08 |
![]() |
5 ms | 4 MB |
g++-13 | small_09 |
![]() |
5 ms | 4 MB |
clang++-18 | example_00 |
![]() |
8 ms | 4 MB |
clang++-18 | max_random_00 |
![]() |
161 ms | 7 MB |
clang++-18 | max_random_01 |
![]() |
151 ms | 7 MB |
clang++-18 | max_random_02 |
![]() |
155 ms | 7 MB |
clang++-18 | max_random_03 |
![]() |
158 ms | 7 MB |
clang++-18 | max_random_04 |
![]() |
158 ms | 7 MB |
clang++-18 | random_00 |
![]() |
126 ms | 6 MB |
clang++-18 | random_01 |
![]() |
128 ms | 7 MB |
clang++-18 | random_02 |
![]() |
86 ms | 4 MB |
clang++-18 | random_03 |
![]() |
41 ms | 7 MB |
clang++-18 | random_04 |
![]() |
48 ms | 6 MB |
clang++-18 | small_00 |
![]() |
6 ms | 4 MB |
clang++-18 | small_01 |
![]() |
5 ms | 4 MB |
clang++-18 | small_02 |
![]() |
5 ms | 4 MB |
clang++-18 | small_03 |
![]() |
5 ms | 4 MB |
clang++-18 | small_04 |
![]() |
5 ms | 4 MB |
clang++-18 | small_05 |
![]() |
5 ms | 4 MB |
clang++-18 | small_06 |
![]() |
5 ms | 4 MB |
clang++-18 | small_07 |
![]() |
5 ms | 4 MB |
clang++-18 | small_08 |
![]() |
5 ms | 4 MB |
clang++-18 | small_09 |
![]() |
5 ms | 4 MB |