package DataStructures.Trees;public class FenwickTree {private int n;private int fen_t[];/* Constructor which takes the size of the array as a parameter */public FenwickTree(int n) {this.n = n;this.fen_t = 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 1i += 1;while (i <= n) {fen_t[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 1i += 1;int cumSum = 0;while (i > 0) {cumSum += fen_t[i];i -= i & (-i);}return cumSum;}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。