#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define vll vector<ll>
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define fr first
#define se second
#define pb push_back
#define vvll vector<vll>
#define pll pair<ll, ll>
#define vbool vector<bool>
#define INF 10000000000000000

using namespace std;
using namespace __gnu_pbds;

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

    ll n, q;
    cin >> n >> q;
    vll a(n);

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

    while (q --) {
        ll x, l, r;
        cin >> x;
        if (x == 1){
            cin >> l;
            l --;
            a[l] *= -1;
        }
        else {
            cin >> l >> r;
            l --;
            r --;
            vbool us(n, 0);
            ll x = -1;
            vll k(n, 0);
            for (int i = l; i <= r; i ++) {
                if (a[i] == 1) {
                    us[i] = 1;
                    x = i;
                }
            }
            for (int i = r; i >= l; i --) {
                if (i == r) k[i] = 0;
                else k[i] = k[i+1];
                k[i] += us[i];
            }
            ll k1 = 0, minl = INF;

            for (int i = l; i <= r; i ++) {
                if (a[i] == 1) {
                    k1 ++;
                    continue;
                }
                minl = min(minl, k[i]);
                if (i > x) break;
                //minl = min(minl, k);

                if (min(k1, minl) > 0) {
                    us[i] = 1;
                    minl --;
                    k1 --;
                }
                //cout << minl << ' ' << q << endl;
            }

            ll res = 0;
            for (int i = l; i <= r; i ++) {
                //cout << us[i];
                if (us[i]) res ++;
            }
            //cout << endl;

            cout << res << endl;
        }
    }



}