algorithm - 3d 芬威克树

标签 algorithm 3d tree fenwick-tree

我有一个三维fenwick tree数据结构。 我需要计算从 (x0, y0, z0)(x, y, z)

的某些段的总和

包容排除的公式是什么? 例如,对于 2D 变体,它是

s = sum(x, y) - sum(x, y0 - 1) - sum(x0 - 1, y) + sum(x0 - 1, y0 - 1)

提前致谢

http://www.comp.nus.edu.sg/~stevenha/ft.pdf

这是二维案例: enter image description here

最佳答案

公式总共涉及8次计算

value1 = sum(x,y,z)- sum(x0-1,y,z)  - sum(x,y0-1,z) + sum(x0-1,y0-1,z)

value2 = sum(x,y,z0-1) - sum(x0-1,y,z0-1) - sum(x,y0-1,z0-1)  + sum(x0-1,y0-1,z0-1)


final answer = value1 - value2

代码的时间复杂度是8 (logn)^3

您如何可视化。

1> assume it as a cube.

2> value 1 gives answer for upper square layer of cube, but it include sum upto 0 in z-axis. 

You only want upto z0, so you have subtract that extra part(from z0 to 0, and that is value2).

关于algorithm - 3d 芬威克树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11713562/

相关文章:

algorithm - 了解动态规划中的基本情况

algorithm - 射线-胶囊相交

opengl-es - 在 Symbian^3 中通过 VBO 方法加载 3D 对象时获取 KERN-EXEC 3,为什么?

javascript - CSS 3D变换以制作给定边长的梯形

algorithm - 二叉树查找最接近且大于 key 的数字

c++ - 如何判断一个点是否在矩形内?

java - 寻求正确的模式以将相同的规则应用于不同的数据集

android - 了解 Android 中的 android.graphics.Camera 对象

c - 这个功能如何运作? (二叉搜索树递归)

java - 关于在 android 中使用基数树在 240k 单词列表中进行英语词典单词查找的问题