#include#include using namespace std; const int N = 100010; int n,m; int a[N], s[N]; int main() { scanf("%d%d", &n, &m); for ( int i = 1; i <= n; i++ ) scanf("%d", &a[i]); for ( int i = 1; i <= n; i++ ) s[i] = s[i - 1] + a[i]; // 前缀和的初始化 while ( m-- ) { int l, r; scanf("%d%d", &l, &r); printf("%dn", s[r] - s[l - 1]); // 计算区间和 } return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)