#include <stdio.h> #include <stdlib.h> int main() { int n, q; if (scanf("%d %d", &n, &q) != EOF) { int* arr = (int*)malloc(sizeof(int) * n); for(int i = 0; i < n; i++) { scanf("%d", &arr[i]); } int l, r; long long* sum = (long long*)malloc(sizeof(long long) * (n + 1)); sum[-1] = 0; for(int i = 0; i < n; i++) { sum[i] = arr[i] + sum[i - 1]; } for(int i = 0; i < q; i++) { scanf("%d %d", &l, &r); printf("%lld\n", sum[r - 1] - sum[l - 2]); } free(arr); } else { printf("no input"); } return 0; }