#include <bits/stdc++.h>
using namespace std;

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

    int n, q;
    cin >> n >> q;
    int a[n + 5], c[n + 5];
    c[0] = 0;
    for (int i = 1; i <= n i++)
    {
        cin >> a[i];
        c[i] = c[i - 1];
        if (a[i] == 1) c[i]++;
    }
    for (int qq = 0; qq < q; qq++)
    {
        int type, l, r;
        cin >> type >> l >> r;
        if (a[l] == 1 && a[r] == 1)
        {
            cout << r - l + 1 << "\n";
        }
        else cout << r - l << "\n";
    }
}
