原题链接:
题解:
套板子即可
代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[N], s[N];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1;i <= n;i++) cin >> a[i];
for (int i = 1;i <= n;i++) s[i] = s[i - 1] + a[i];
while (m--) {
int a, b;
cin >> a >> b;
cout << s[b] - s[a - 1] << endl;
}
}