O(log(n)) Range Queries on (modified) Fenwick Tree Without Inverse Operation

Правка en1, от estoy-re-sebado, 2023-10-16 19:19:12

This blog came about because of some pretty random events.

  • A while back ponysalvaje explained me how the Fenwick Tree works and some cool tricks you can do with it.

  • Some time later, I saw this blog. As soon as I read the first paragraph, I stopped and tried to invent such a data structure myself. I thought of storing jumps of distance $$$LSB(depth_u)$$$. This works, but the ancestor queries are actually $$$O(\log(N)^{2})$$$ in the worst case. Adding new leaf requires an ancestor query, but it happens to actually be $$$O(\log(N))$$$ because of some happy accidents.

  • This made me realize that you can compute any range query on an FT, not just prefixes (but in $$$O(\log(N)^{2})$$$ time). Because of this, I wrote this other blog.

  • Then, I read the original blog and thought that the idea presented in it can also be used to compute range queries and updates. (I didn't prove it but it seems obvious that each position in the array is covered by, at most, $$$\log(N)$$$ ranges)

Теги range query, fenwick tree, binary indexed tree, binary lifting

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en10 Английский estoy-re-sebado 2023-11-22 23:15:33 3715 Make the data structure use O(N) memory, add section on better point updates.
en9 Английский estoy-re-sebado 2023-11-22 20:54:36 32
en8 Английский estoy-re-sebado 2023-11-22 18:07:39 88
en7 Английский estoy-re-sebado 2023-11-22 06:01:59 209
en6 Английский estoy-re-sebado 2023-11-22 05:31:38 13 Tiny change: 'mp[MAXN+1];\nlong long tree[MAXN' -> 'mp[MAXN+1], tree[MAXN'
en5 Английский estoy-re-sebado 2023-11-22 05:30:43 31
en4 Английский estoy-re-sebado 2023-11-22 05:23:45 170
en3 Английский estoy-re-sebado 2023-11-22 05:21:40 97
en2 Английский estoy-re-sebado 2023-11-22 05:20:28 3085 Tiny change: 'onstructed, but this ' -> 'onstructed but this ' (published)
en1 Английский estoy-re-sebado 2023-10-16 19:19:12 1161 Initial revision (saved to drafts)