Calculate the sum of all sub-arrays with given indices
You can use the concept of segment trees. Check this link:
https://en.wikipedia.org/wiki/Segment_tree and https://www.geeksforgeeks.org/segment-tree-set-1-sum-of-given-range/
The above link works for finding the sum of all the elements in a given range [i,j]. However, you can use the same approach to find the minimum element in the range [i,j] in $O(\log n)$ time. The idea is that you can break the range [i,j] into $O(\log n)$ smaller ranges, and for each of these ranges you already know their minimum values via some binary tree (built during pre-processing step). Thus, you can take the minimum over all these small ranges, and it will give the overall minimum in the range [i,j] in $O(\log n)$ time.

Building the binary tree comes under the pre-processing step and it will only take $O(n)$ time.
Also, there are $m$ queries and each query takes $O(\log n)$ time. The overall time complexity would be $O(n + m \log n)$. Since $m &lt; n$, the overall complexity is $O(n \log n)$.