输入一个长度为 n 的整数序列。
每个询问输入一对 {s,e};对于每个询问,输出原序列中从第 s个数到第 e个数的和。
#include <iostream> #include <cstdio> using namespace std; const int N = 100010; int n, m; int a[N], s[N]; int main () { cin >> n >> m; for (int i = 1; i <= n; i++) { scanf ("%d", &a[i]); s[i] = s[i - 1] + a[i]; } while (m--) { int l, r; cin >> l >> r; printf ("%d\n", s[r] - s[l - 1]); } return 0; }
标签:前缀,int,个数,数组,序列,include From: https://www.cnblogs.com/leetothemoon/p/16939718.html