Link to this code: https://cses.fi/paste/d9d8c81cf5f57e64692632/
#include<iostream>
using namespace std;
#define ll long long
int main(){
  int n,q,l,r;
  cin>>n>>q;
  ll a[n+1];
  a[0]=0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    a[i]+=a[i-1];
  }
  while(q--){
    cin>>l>>r;
    cout<<a[r]-a[l-1]<<endl;
  }
  return 0;
}