How can we calculate weighted cumulative sum of squares with prefix range updates by one?

不问归期 提交于 2020-05-10 06:45:32

问题


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.

来源:https://stackoverflow.com/questions/61122170/how-can-we-calculate-weighted-cumulative-sum-of-squares-with-prefix-range-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!