前缀和应该也是体现了递归的思想吧
#include <iostream>
using namespace std;
const int N = 100010;
int a[N], b[N];
int main()
{
int m, n, l, r;
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i ++ ) cin >> b[i];
for(int i = 1; i <= n; i ++ )
a[i] = a[i - 1] + b[i];
while(m -- )
{
scanf("%d%d", &l, &r);
printf("%d\n", a[r] - a[l - 1]);
}
}