#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second
#define pb push_back

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, q, x, l, r;
    cin >> n >> q;
    vector<int> v(n+1), pref(n+1), suf(n+1);
    pref[0] = 0;
    for (int i=1; i<=n; i++) {
        cin >> v[i];
        pref[i] = pref[i-1] + (v[i] == 1);
    }
    suf[n] = (v[n] == 1);
    for (int i=n-1; i>0; i--) {
        suf[i] = suf[i+1] + (v[i] == 1);
    }
    while (q--) {
        cin >> x >> l >> r;
        cout << max(0, (r-l+1-(v[l] == -1) - (v[r] == -1))) << "\n";
    }
}