-->

How can we calculate weighted cumulative sum of sq

2020-06-06 04:35发布

问题:

Given an array A with n elements which starts with all 0s and another array W also with n elements (all greater than 0), we want to perform the following operation repeatedly;

For a given k, increment A[0], A[1], .... A[k] each by 1, and report the value of A[0]^2 * W[0] + A[1]^2 * W[1] + ... + A[n-1]^2 * W[n-1].

Looking for an O(log n) solution (per query), or faster.