// #define _GLIBCXX_DEBUG
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define all(a) (a).begin(), (a).end()

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

    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int i;
            cin >> i;
            i--;
            a[i] = -a[i];
        } else {
            int l, r;
            cin >> l >> r;
            // cerr << l << ' ' << r << endl;
            l--, r--;
            int c = 0, res = 0, l1 = 0, l2 = n, j = 0;
            for (int i = l; i <= r; i++) c += a[i] == 1;
            for (int i = l; i <= r; i++) {
                if ((l1 == 0 || l2 == 0) && a[i] == -1) continue;
                if (a[i] == 1) {
                    l1++;
                    l2 = min(l2, c - j - 1);
                    j++;
                } else l1--, l2--;
                res++;
            }
            cout << res << '\n';
        }
    }
}