Prefix sums
easyprefix[r+1] − prefix[l] cancels the shared head and leaves exactly a[l..r]. One linear pass buys constant-time range sums for every query afterwards.
Best
O(n) buildWorst O(1) per querySpace O(n)Loading the prefix sums engine…