Skip to main content
←
Architecture Workspace
Arch
OS
Workspaces
/
Search blueprints, commands…
⌘K
Build
Learn
Blueprint
▾
Share
Sign in
Menu ▾
ArchOS Studio
Hydrating 525 executable blueprints & local workspace…
ALGORITHM CANVAS · SEGMENT / FENWICK TREE · TIME O(log N) · SPACE O(N)
Segment Tree Range-Sum Aggregation
Solve Timed Cold Drill →
✕ Topology View
Pre-aggregate binary range intervals bottom-up so point updates AND arbitrary range queries both complete in O(log N).
TREE TREE (7 ACTIVE NODES)
0
0
0
3
8
6
4
◀ Prev
▶ Play
Next ▶
STEP 1/4 · L5
1x
arr
=[3,8,6,4]
tree
=[0,0,0,3,8,6,4]
PYTHON 3.12 · INSTANT PREVIEW
▸ Trace Live Python (Pyodide)
1
def build_seg_tree(arr):
2
n = len(arr)
3
tree = [0] * (2 * n)
4
for i in range(n):
5
tree[n + i] = arr[i]
6
for i in range(n - 1, 0, -1):
7
tree[i] = tree[2 * i] + tree[2 * i + 1]
8
return tree[1:]
CALL: