1.前缀和
预处理公式
代码:
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int a[10005];
int main() {
int n, m;
cin >> n;
cin >> m;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
}
for (int i = 1; i <= m; i ++) {
int l, r;
long long tot = 0;
cin >> l >> r;
for (int j = l; j <= r; j ++) {
tot += a[j];
}
cout << tot << endl;
}
return 0;
}
标签:std,10005,前缀,int,cin,一维,include
From: https://blog.csdn.net/dedsad/article/details/144250366