AcWing 795 前缀和
作者:互联网
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int q[N];
int s[N];
//一维前缀和
int main() {//优化输入
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> q[i];
s[i] = s[i - 1] + q[i];
}
while (m--) {
int l, r;
cin >> l >> r;
printf("%d\n", s[r] - s[l - 1]);
}
return 0;
}
标签:795,false,前缀,int,cin,sync,传送门,AcWing 来源: https://www.cnblogs.com/littlehb/p/15761158.html