/*
前缀和
定义:s[i]表示原数组前i个数的和
作用:求任意区间[l, r]的和的时间复杂度从循环加的O(n) 到 s[r] - s[l-1] 的时间复杂度O(1)
eg: s[3] = a1 + a2 + a3;
s[5] = a1 + a2 + a3 + a4 + a5;
s[4, 5] = s[5] - s[3];//前五个数减去前三个数
为了统一公式,把s[0]设为0
eg:s[3] = s[1, 3] = s[3] - s[0];
*/
#include <iostream>
using namespace std;
const int N = 1e5 + 10;//比题目设置的最大值再大一点,防止发生数组越界问题
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]);
//求前缀和数组
s[0] = 0;
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("%d\n", s[r] - s[l - 1]);
}
return 0;
}