total can be written in exactly one way as a sum of distinct powers of two (that is its binary form). List those powers in increasing order to get the array pieces, indexed from 0.
You are given queries queries, where queries[i] = [l, r]. The answer to a query is the product pieces[l] · pieces[l+1] · ... · pieces[r]. It can be huge, so return it modulo 10⁹ + 7.
Return the answers to all the queries, in order.total=13, queries=[[0, 1], [1, 2], [2, 2]] → [4, 32, 8]
13 = 1 + 4 + 8, so the pieces are [1, 4, 8]. The products are 1·4 = 4, 4·8 = 32 and just 8.
total=6, queries=[[0, 1]] → [8]
6 = 2 + 4, the pieces are [2, 4], and their product is 8.
total ≤ 10⁹queries.length ≤ 10⁵l ≤ r < pieces.lengthtotal=13, queries=[[0, 1], [1, 2], [2, 2]]
[4, 32, 8]
Run checks the first 3 tests in your browser. Submit checks all 55 tests on the server, hidden ones included.