题解 | #【模板】前缀和#
【模板】前缀和
https://www.nowcoder.com/practice/acead2f4c28c401889915da98ecdc6bf
#include <bits/stdc++.h> using namespace std; int n,q; const int N = 100010; long long a[N],dp[N];//状态转移方程 int main() { scanf("%d%d",&n,&q); for(int i = 1;i<=n;i++) { scanf("%lld",&a[i]); dp[i] = dp[i-1] + a[i]; } while(q--) { int l,r; scanf("%d%d",&l,&r); printf("%lld\n",dp[r]-dp[l-1]); } return 0; }