Kyopro Library
読み取り中…
検索中…
一致する文字列を見つけられません
fenwick_tree.hpp
[詳解]
1
#
pragma
once
2
#
include
"../../kyopro_library/template.hpp"
3
4
struct
FenwickTree
{
5
FenwickTree
()=
default
;
6
FenwickTree
(
int
n) {
7
this
->n=n;
8
dat.assign(n,0);
9
}
10
void
add
(
int
i, ll x) {
11
i++;
12
while
(i<=n) dat[i-1]+=x, i+=i&-i;
13
}
14
ll
sum
(
int
l,
int
r) {
return
sum(r)-sum(l); }
15
ll
operator
[](
int
i) {
return
sum
(
i
,
i+1
)
; }
16
int
size
() {
return
n; }
17
18
private
:
19
int
n;
20
vector<ll> dat;
21
ll sum(
int
r) {
22
ll ret=0;
23
while
(r>0) ret+=dat[r-1], r-=r&-r;
24
return
ret;
25
}
26
};
FenwickTree
Fenwick Tree
Definition
fenwick_tree.hpp:4
FenwickTree::FenwickTree
FenwickTree(int n)
Definition
fenwick_tree.hpp:6
FenwickTree::operator[]
ll operator[](int i)
Definition
fenwick_tree.hpp:15
FenwickTree::add
void add(int i, ll x)
Definition
fenwick_tree.hpp:10
FenwickTree::FenwickTree
FenwickTree()=default
FenwickTree::sum
ll sum(int l, int r)
Definition
fenwick_tree.hpp:14
FenwickTree::size
int size()
Definition
fenwick_tree.hpp:16
data_structure
fenwick_tree.hpp
構築:
1.13.2