c/c++语言开发共享树状数组

大佬的解释 https://www.cnblogs.com/hsd-/p/6139376.html …

lowbit(x)=2^k
int lowbit(int t) { return t & (-t); }

单点更新
x是更改的位置,y是更改的值
void add(int x, int y) { for (int i = x; i <= n; i += lowbit(i)) tree[i] += y; }

求a数组中前x项的和 
int getsum(int x) { int ans = 0; for (int i = x; i > 0; i -= lowbit(i)) ans += tree[i]; return ans; }

大佬的解释

https://www.cnblogs.com/hsd-/p/6139376.html

 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/603420.html

(0)
上一篇 2021年5月11日
下一篇 2021年5月11日

精彩推荐