全部数据点击查看

代码

#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn = 1e5 + 5;
int n, q, sum[maxn];
int main() {
    scanf("%d%d", &n, &q);
    int x, y;
    for (int i = 1; i <= n; ++i) scanf("%d", &x), sum[i] = sum[i - 1] + x;
    while (q--) {
        scanf("%d%d", &x, &y);
        printf("%d\n", sum[y] - sum[x - 1]);
    }
}