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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, q;
    cin >> n >> q;
    ll values[i];
    for(ll i = 0; i<n; i++) cin >> values[i];
    for(ll i = 0; i<q; i++){
        ll type, first, second;
        cin >> type >> first >> second;
        first--;
        second--;
        if(values[first]==values[second] && values[first]==1) cout << second-first+1 << '\n';
        else if(values[first]!=values[second]) cout << second-first << '\n';
        else cout << second-first-1 << '\n';
    }
}
