Skip to content

Commit 111a9ae

Browse files
committed
make FenwickTree guide
1 parent b92d30c commit 111a9ae

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎FenwickTree/FenwickTree.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# クラス FenwickTree
2+
- - -
3+
4+
長さ $N$ の long型配列に対し,
5+
6+
* 要素の1点変更
7+
* 区間の要素の総和
8+
9+
を $O(\log N)$ の時間で求めることができるデータ構造です.
10+
11+
12+
## コンストラクタ
13+
### FenwickTree
14+
```java
15+
public FenwickTree(int n)
16+
```
17+
18+
長さ $n$ の配列 $a_0, a_1, \dots, a_{n-1}$を作ります. 初期値はすべて0です.
19+
計算量: $O(n)$
20+
21+
## メソッド
22+
### add
23+
```java
24+
public void add(int p, long x)
25+
```
26+
配列の第$p$要素に$x$を加える. すなわち, `a[p] += x` のこと.
27+
計算量: $O(\log N)$
28+
29+
### sum
30+
```java
31+
public long sum(int l, int r)
32+
```
33+
$a_l + a_{l+1} + \dots + a_{r-1}$の値を返す. 計算量: $O(\log n)$

0 commit comments

Comments
 (0)