Zkw线段树 «COMPLETE»

The zkw segment tree is an elegant, highly efficient alternative to the classic recursive segment tree. Its iterative nature yields simpler code, lower constant factor, and smaller memory footprint. While it does not simplify lazy propagation, it excels in point update / range query scenarios and is an essential tool for performance‑sensitive applications.

int query(int l, int r) // inclusive l += N, r += N; int res = 0; while (l <= r) if (l & 1) res += tree[l++]; if (!(r & 1)) res += tree[r--]; l >>= 1; r >>= 1; zkw线段树