I have an array a[0..n - 1]. I have 2 types operations:
- sum l r: sum = a[l] * 1 + a[l+1] * 2 + ... + a[r] * (r - l)
- update index value: a[index] = value
How can I modify standart sum segment tree for this task?
I have an array a[0..n - 1]. I have 2 types operations:
How can I modify standart sum segment tree for this task?
Copyright © 2021 Jogjafile Inc.
Store a second segment tree for sums of the array
b, whereb[i] = (i+1) * a[i]. Then, settinga[index] = valueshould also update the second segment tree withb[index] = value * (index + 1).To calculate the sum you want, given the ability to query the normal subarray sums of
aandb: