    #include <bits/stdc++.h>
    #include <random>

    using namespace std;

    #define ll long long
    #define endl '\n'
    #define ld long double
    #define pb push_back

    const ll clasik = 7e5+7;
    const ll INF = 1e17;
    const ll mod = 1e9+7;
    const ll mln = 1e6+111;

    ll df[mln];

    void solve() {

        ll n , q;

        cin>>n>>q;

        for (int i = 1 ; i<=n ; i++) {
            cin>>df[i];
        }

        ll type , l , r;

        for (int i = 1 ; i <= q ; i++) {
            cin>>type;
            if (type == 1) {
                cin>>l;
                df[l] = (df[l] == -1 ? 1 : -1);
                continue;
            }
            cin>>l>>r;
            ll cnt = 0;
            vector <ll> v;
            for (int j = l ; j<=r ; j++) {
                if (df[j] == 1) cnt++;
            }

            ll k = 0;

            for (int j = l ; j<=r ; j++) {
                if (df[j] == 1) {
                    v.pb(df[j]);
                    k++;
                    cnt --;
                }
                else {
                    if (k >= 1 && cnt >= 1) {
                        //cout<<k<<" "<<cnt<<endl;
                        v.pb(-1);
                        k--;
                        cnt--;
                    }
                }
            }

            cout<<v.size()<<endl;
        }

    }

    signed main() {
        
        int t = 1;

        //cin>>t;

        while(t--) solve();

        return 0;
    }