#include<bits/stdc++.h>
using namespace std;
int n,m;
int l,r;
const int N=1e5+10;
int a[N];
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
sum[i]=sum[i-1]+a[i];
}
int ans=0;
while(n--){
cin>>l>>r;
ans=sum[r]-sum[l-1];
cout<<ans<<endl;
}
}
标签:std,前缀,int,sum,cin,ans From: https://www.cnblogs.com/chenxinyue/p/17227335.html