Sums of many ranges
Given a list of integers nums and a list queries, where each query is a pair [lo, hi] with 0 <= lo <= hi < len(nums), return a list with the sum of nums[lo] through nums[hi] (both ends included) for each query, in the order given.
There can be far more queries than numbers: after one pass over nums, each query should take O(1). Values may be negative and queries may be empty.
Besides the tests, one large input (8,000 queries over 3,000 numbers) with a ~300 ms limit (scaled to your device's speed): brute force won't pass.
Examples
range_sums([3,1,4,1,5], [[0,2],[1,3],[4,4]])→[8,6,5]range_sums([2,-7,5,-1], [[0,3],[1,1],[2,3]])→[-1,-7,4]range_sums([10], [[0,0],[0,0]])→[10,10]