File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,10 @@ public FenwickTree(long[] data) {
1616 build (data );
1717 }
1818
19+ public void set (int p , long x ){
20+ add (p , x - get (p ));
21+ }
22+
1923 public void add (int p , long x ){
2024 assert (0 <=p && p <_n );
2125 p ++;
@@ -29,6 +33,10 @@ public long sum(int l, int r){
2933 return sum (r )-sum (l );
3034 }
3135
36+ public long get (int p ){
37+ return sum (p , p +1 );
38+ }
39+
3240 private long sum (int r ){
3341 long s = 0 ;
3442 while (r >0 ){
Original file line number Diff line number Diff line change @@ -32,6 +32,19 @@ public void add(int p, long x)
3232配列の第$p$要素に$x$を加える. すなわち, ` a[p] += x ` のこと.
3333計算量: $O(\log N)$
3434
35+ ### set
36+ ``` java
37+ public void set(int p, long x)
38+ ```
39+ 配列の第$p$要素を$x$に変更する. すなわち, ` a[p] = x ` のこと.
40+ 計算量: $O(\log N)$
41+
42+ ### get
43+ ``` java
44+ public long get(int p)
45+ ```
46+ 配列の第$p$要素を取得する. 計算量: $O(\log n)$
47+
3548### sum
3649``` java
3750public long sum(int l, int r)
You can’t perform that action at this time.
0 commit comments