Zkw线段树 -
单点修改直接定位到叶子节点 M + pos ,然后一路向父节点更新。
Lazy propagation can be implemented by storing pending tags in a separate array lazy[2*N] and pushing down along the path during updates/queries. However, the iterative nature becomes less elegant. For complex range updates, many programmers still prefer recursive lazy trees. zkw线段树
return res;
:所有原始数据作为叶子节点直接存放在数组后半部分。操作时从叶子开始直接向根部跳跃,复杂度虽同为 ,但实际运行效率更高。 二、 基础操作实现 1. 建树与初始化 首先确定 M 的大小,即第一个大于或等于 的 2 的幂。 zkw线段树
This works in $O(\log N)$ and is much faster than binary search on prefix sums. zkw线段树