/
NikolayIvkin
/
TheAlgorithms
Обзор
Документация
Войти
/
NikolayIvkin
/
TheAlgorithms
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/com/thealgorithms/datastructures/trees/FenwickTree.java
35 строк
909 B
S. Utkarsh
style: enable `MemberName` in checkstyle (#5193)
29 май 2024, 23:44
Не верифицирован
29 май 2024, 23:44
a6e873d
Код
Авторство
О чём код?
package com.thealgorithms.datastructures.trees; public class FenwickTree { private int n; private int[] fenTree; /* Constructor which takes the size of the array as a parameter */ public FenwickTree(int n) { this.n = n; this.fenTree = new int[n + 1]; } /* A function which will add the element val at index i*/ public void update(int i, int val) { // As index starts from 0, increment the index by 1 i += 1; while (i <= n) { fenTree[i] += val; i += i & (-i); } } /* A function which will return the cumulative sum from index 1 to index i*/ public int query(int i) { // As index starts from 0, increment the index by 1 i += 1; int cumSum = 0; while (i > 0) { cumSum += fenTree[i]; i -= i & (-i); } return cumSum; } }