题解 | #【模板】前缀和#
【模板】前缀和
https://www.nowcoder.com/practice/acead2f4c28c401889915da98ecdc6bf
#include <iostream> using namespace std; const int N = 100010; long long a[N], s[N]; int main() { int n, m; cin >> n >> m; for(int i = 1; i <= n; i ++){ cin >> a[i]; s[i] = s[i - 1] + a[i]; } while(m --){ int l, r; cin >> l >> r; cout << s[r] - s[l - 1] << endl; } return 0; }