#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

int main() {
#ifndef DEBUG
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    int n, q;
    cin >> n >> q;

    vector<int> arr(n);

    for (auto& it : arr) {
        cin >> it;
    }

    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;

        if (t == 1) {
            int p;
            cin >> p;

            p -= 1;
            arr[p] = -arr[p];
        } else if (t == 2) {
            int l, r;
            cin >> l >> r;

            int len = 0;
            int delta = 0;
            int delta2 = 0;

            for (int j = l - 1; j < r; j++) {
                delta2 += (arr[j] == 1);
            }

            for (int j = l - 1; j < r; j++) {
                if (arr[j] == 1) {
                    delta += 1;
                    delta2 -= 1;
                    len += 1;
                } else if (delta > 0 && delta2 > 0) {
                    delta -= 1;
                    len += 1;
                }
            }

            cout << len << "\n";
        }
    }

    return 0;
}
