Algorithm visualizer
Pick an algorithm, enter your own numbers or use a preset, then step through the run. The pseudocode and the explanation follow each step.
Build P, where P[i] is the sum of the first i values. Then the sum of any range [l, r] is P[r+1] - P[l].
Add a query that covers a single index. Confirm that P[r+1] - P[l] gives that one value.
Step 1 of 11
P[0] = 0. The empty prefix sums to 0.