Intermediate · 20 minYou are hereReadPrefix sumsStoring the running totals of an array gives the sum of any range in one subtraction, but changing one value means updating every total after it.
Intermediate · 30 minYou are hereReadSegment treesA tree whose every node holds the sum of a stretch of the array answers any range sum and any update in about log₂ n steps.
Intermediate · 20 minYou are hereReadFenwick treesAn array in which cell i holds the sum of a stretch whose length is the lowest set bit of i gives prefix sums and updates in about log₂ n steps with a few lines of code.