下面是代码解释
#include <cstdio>
int fore[1000001];
int main(){
int N, M;
scanf("%d %d", &N, &M);
int temp, n, m;
for(int i = 1; i <= N; i ++){
scanf("%d", &temp);
fore[i] = fore[i - 1] + temp;
}
for(int i = 1; i <= M; i ++){
scanf("%d %d", &m, &n);
printf("%d\n", fore[n] - fore[m - 1]);
}
return 0;
}