Templates -- Meow
1.1.4
A C++ template which is unable and also not allowed to compile to obj-file first.
|
極度簡化的 SegmentTree
已無區間更新的操作
More...
#include "BinaryIndexTree.h"
Public Member Functions | |
BinaryIndexTree () | |
constructor More... | |
BinaryIndexTree (size_t size, Value const &value) | |
constructor More... | |
BinaryIndexTree (BinaryIndexTree const &tree2) | |
constructor More... | |
void | reset (size_t size, Value const &init) |
將資料洗掉, 重設 More... | |
void | update (size_t index, Value const &value) |
將array中第 index (從零算起)個element多加上指定的值 More... | |
Value | query (ssize_t index) const |
詢問 0~index 的區間值 More... | |
極度簡化的 SegmentTree
已無區間更新的操作
一般來說只能用在維護區間總和, 維護區間最大值只有在特殊情況才可以, 即 針對每個元素, 每次update() 的值一定會大於等於原本的值 . 若要用區間最大值 , 則 Value 的 operator+
要寫成 std::max
(...)
Definition at line 21 of file BinaryIndexTree.h.
|
inline |
constructor
Definition at line 28 of file BinaryIndexTree.h.
|
inline |
constructor
[in] | size | 要維護的區間大小 [0,size) |
[in] | value | 預設值 |
Definition at line 37 of file BinaryIndexTree.h.
|
inline |
constructor
將另一個 BinaryIndexTree
原封不動的複製過來
[in] | tree2 | 另外一個 BinaryIndexTree |
Definition at line 47 of file BinaryIndexTree.h.
|
inline |
詢問 0~index 的區間值
時間複雜度O(logN)
[in] | index | 指定的index |
Definition at line 90 of file BinaryIndexTree.h.
|
inline |
將資料洗掉, 重設
時間複雜度O(N)
[in] | size | 要維護的區間大小 [0,size) |
[in] | init | 預設值 |
Definition at line 60 of file BinaryIndexTree.h.
|
inline |
將array中第 index (從零算起)個element多加上指定的值
時間複雜度O(logN)
[in] | index | 指定的index |
[in] | value | 指定的值 |
Definition at line 74 of file BinaryIndexTree.h.