This documentation is automatically generated by online-judge-tools/verification-helper
#include "data_structure/binary_indexed_tree.hpp"binary_indexed_tree<T>(int n) : 要素数 $N$ の BIT を構築するadd(int i, T x) : $i$ 番目に $x$ を加算する $O(\log(N))$sum(int i) : $[1, i]$ の総和を求める $O(\log(N))$#pragma once
#include<cassert>
#include<vector>
template<typename T>struct binary_indexed_tree {
int n;
std::vector<T> BIT;
binary_indexed_tree(int n_) : n(n_ + 1), BIT(n, 0) {}
void add(int i, T x){
assert(1 <= i && i <= n);
for(int idx = i;idx < n;idx += (idx & -idx)){
BIT[idx] += x;
}
}
T sum(int i) {
assert(1 <= i && i <= n);
T ret = 0;
for(int idx = i;idx > 0;idx -= (idx & -idx)){
ret += BIT[idx];
}
return ret;
}
};#line 2 "data_structure/binary_indexed_tree.hpp"
#include<cassert>
#include<vector>
template<typename T>struct binary_indexed_tree {
int n;
std::vector<T> BIT;
binary_indexed_tree(int n_) : n(n_ + 1), BIT(n, 0) {}
void add(int i, T x){
assert(1 <= i && i <= n);
for(int idx = i;idx < n;idx += (idx & -idx)){
BIT[idx] += x;
}
}
T sum(int i) {
assert(1 <= i && i <= n);
T ret = 0;
for(int idx = i;idx > 0;idx -= (idx & -idx)){
ret += BIT[idx];
}
return ret;
}
};