Two points:
Prefix sums convert range queries into constant-time subtractions. This is a telescoping pattern: .
Precomputing cumulative values (sums, products, XORs) speeds up repeated queries. The pattern: spend once to answer later.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
summary
Two points:
Prefix sums convert range queries into constant-time subtractions. This is a telescoping pattern: .
Precomputing cumulative values (sums, products, XORs) speeds up repeated queries. The pattern: spend once to answer later.