CSES - Shared codeLink to this code: https://cses.fi/paste/32b8635571e24e677bbbda/
#include <bits/stdc++.h>

#define range(it, a, b) for (ll it = a; it < b; it++)
#define all(x) begin(x), end(x)
#define ll long long
#define ull unsigned long long
#define INF64 ((ll) 1 << 60)
#define INF32 (1 << 30)
#define uset unordered_set
#define umap unordered_map 
#define pqueue priority_queue

using namespace std;

void setio (string name) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (name.size()) {
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }   
}

ll n, q;
vector<ll> a;

void solve() {
    cin >> n >> q;
    a.resize(n);
    range(i, 0, n) {
        cin >> a[i];
        if (i) a[i] += a[i - 1];
    }

    ll l, r;
    while (q--) {
        cin >> l >> r;
        l--; r--;
        cout << (a[r] - (l ? a[l - 1] : 0)) << '\n'; 
    }
}

int main () {
    setio("");
    ll t = 1; 
    // cin >> t;
    while (t--) solve();
}