I have a list of $n$ non-overlapping intervals, namely $[a_1,a_2],[a_2,a_3],...,[a_n,n_{n+1}], a_i \in \mathbb{N}$.
Each of these intervals has a corresponding value $v_i$ corresponding to it.
Now I have another interval $[x,y], a_1 \leq x < y \leq a_{n+1}$. I want to query the $n$ intervals and find the sum of values of the overlapping intervals with it in $O(\log n)$ time.
To make it clearer, I'll give an example.
Suppose the intervals are $[0,2],[2,4],[4,10]$ with values corresponding to $1,3,5$.
For the interval $[0,3]$, the first and second intervals overlap with it so a total value of 1+3=4.
For the interval $[0,5]$, all three overlap with it so a total value of 1+3+5=9.
For the interval $[5,9]$ only the last one overlaps it so the total value is 5.
I know that I can use a segment tree and query the point based on my interval $[a,b]$. However, how would I calculate the sum of all the values of all the intervals in between also in $O(\log n)$?