42 points · by StylifyYourBlog · 10y ago · 8 comments
There are n starting points
There are n ending points
The interval is n/2 in length on average
Thus it requires n * n * (n/2) additions
You said: Generating one partial sum costs n, and
you need to do it n times, ...
I think you need to do it n^2 times.Alternatively you can just perform a prefix sum operation and subtract each (n - k)th element from nth element for results in the kth iteration. This could be even faster.