#include<iostream>
#include<cstdio>
using namespace std;
const int N=100010;
int a[N],s[N];
int n,m,l,r;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
s[i]=s[i-1]+a[i];
}
while(m--){
cin>>l>>r;
cout<<s[r]-s[l-1]<<endl;
}
}
輸入一個長度為 n 的整數序列。
接下來再輸入 m 個詢問,每個詢問輸入一對 l,r。
對于每個詢問,輸出原序列中從第 l 個數到第 r 個數的和。
輸入格式
第一行包含兩個整數 n 和 m。
第二行包含 n 個整數,表示整數數列。
接下來 m 行,每行包含兩個整數 l 和 r,表示一個詢問的區間範圍。
輸出格式
共 m 行,每行輸出一個詢問的結果。
資料範圍
1≤l≤r≤n,
1≤n,m≤100000,
−1000≤數列中元素的值≤1000
輸入樣例:
5 3
2 1 3 6 4
1 2
1 3
2 4
輸出樣例:
3
6
10