Calculate sum of multiple series within array
int pairs[MAXN][2]; wastes memory. You don't need to read all the queries at once:
  for(int i = 0; i &lt; q; i++)
  {
      cin &gt;&gt; L &gt;&gt; R;
      cout &lt;&lt; sumBetween(L - 1, R - 1) &lt;&lt; endl;
  }

works equally well. Besides, the problem statement doesn't say how many queries are there; it could be way more than the size of the array.

Your feeling that you use the wrong algorithm is well founded. Bruteforcing is almost always wrong. Look at the underlying math first. I don't want to spell out everything, just a couple of hints:

\$1*a_{L} + 2*a_{L+1}+ ... + 2^{R-L}*a_{R} = \dfrac{2^L*a_{L} + 2^{L+1}*a_{L+1}+... + 2^R*a_{R}}{2^L}\$

The numerator above is a difference of two partial sums of the \$2^n*a_{n}\$ sequence.

\$1000000007\$ is a prime number, so division by \$2^L\$ modulo 1000000007 is a multiplication by a multiplicative inverse of 2 modulo 1000000007 (which is trivial to find) to the same power.


I hope it is enough to get you going in the right direction. You should be able to answer each query in constant time.