提交时间:2024-09-29 21:32:48

运行 ID: 52271

#include <iostream> #include <vector> #include <cstdio> using namespace std; int main() { int n, q; scanf("%d %d", &n, &q); vector <int> a(n + 5); vector <int> s(n + 5); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { int ans = 0; for (int j = 1; j <= i; j++) ans += a[j]; s[i] = ans; } for (int i = 1; i <= q; i++) { int l, r; scanf("%d %d", &l, &r); printf("%d\n", s[r] - s[l - 1]); } return 0; }