binary-indexed-tree

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 0 s 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

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

被刻印的时光 ゝ 提交于 2020-05-10 06:45:11
问题 Given an array A with n elements which starts with all 0 s 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

How to find the total number of Increasing sub-sequences of certain length with Binary Index Tree(BIT)

﹥>﹥吖頭↗ 提交于 2019-12-20 09:45:30
问题 How can I find the total number of Increasing sub-sequences of certain length with Binary Index Tree(BIT)? Actually this is a problem from Spoj Online Judge Example Suppose I have an array 1,2,2,10 The increasing sub-sequences of length 3 are 1,2,4 and 1,3,4 So, the answer is 2 . 回答1: Let: dp[i, j] = number of increasing subsequences of length j that end at i An easy solution is in O(n^2 * k) : for i = 1 to n do dp[i, 1] = 1 for i = 1 to n do for j = 1 to i - 1 do if array[i] > array[j] for p