dk0001's blog

By dk0001, history, 16 months ago, In English

I am trying to solve the following problem, but I don't know how to begin, Any hint/approach is appreciated

Link to the Problem

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
16 months ago, # |
  Vote: I like it +10 Vote: I do not like it

$$$\sum_{j=L}^{R} \sum_{k=j+1}^{R}(A_j*A_k)=((\sum_{j=L}^{R} A_j)^2-\sum_{j=L}^{R}A_j^2)/2$$$, so you can maintain two segment trees, one for $$$(\sum_{j=L}^{R} A_j)^2$$$, and the second for $$$\sum_{j=L}^{R}A_j^2$$$. To update first segment tree, you will need to maintain $$$\sum_{j=L}^{R} A_j$$$.

»
16 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Represent the summation in a simpler way and then it should become trivial.