#include <bits/stdc++.h>
using namespace std;
pair<int, int> uni(pair<int, int> a, pair<int, int> b){
    int f = a.first;
    int s = b.second;
    if(f < 0)f += (b.first < 0 ? b.first : 0);
    else f += b.first;
    if(s < 0)s += (a.second < 0 ? a.second : 0);
    else s += a.second;
    pair<int, int> r;
    r.first = f;
    r.second = s;
    return r;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, q;
    cin >> n >> q;
    vector<bool> a(n);
    for(int i = 0;i < n;i++){
        int t;
        cin >> t;
        if(t == -1)t++;
        a[i] = t;
    }
    vector<vector<pair<int, int>>> tree (floor(log2(n)) + 1, vector<pair<int, int>>(n));
    for(int i = 0;i <= log2(n);i++){
        for(int j = 0;j < floor(n / pow(2, i));j++){
            if(i == 0){
                if(a[j]){
                    tree[i][j].first = 1;
                    tree[i][j].second = 1;
                }
                else {
                    tree[i][j].first = -1;
                    tree[i][j].second = -1;
                }
            }
            else{
                /*int f = tree[i - 1][j * 2].first;
                int s = tree[i - 1][j * 2 + 1].second;
                if(f < 0)f += (tree[i - 1][j * 2 + 1].first < 0 ? tree[i - 1][j * 2 + 1].first : 0);
                else f += tree[i - 1][j * 2 + 1].first;
                if(s < 0)s += (tree[i - 1][j * 2].second < 0 ? tree[i - 1][j * 2].second : 0);
                else s += tree[i - 1][j * 2].second;
                tree[i][j].first = f;
                tree[i][j].second = s;*/
                tree[i][j] = uni(tree[i - 1][j * 2], tree[i - 1][j * 2 + 1]);
            }
        }
    }
    /*for(int i = 0;i <= log2(n);i++){
        for(int j = 0;j < floor(n / pow(2, i));j++){
            for(int q = 0;q < pow(2, i) - 1;q++)cout << "       ";
            cout << " (" << tree[i][j].first << " " << tree[i][j].second << ") ";
        }
        cout << endl;
    }*/
    for(int i = 0;i < q;i++){
        int aNum;
        cin >> aNum;
        if(aNum == 1){
            int p;
            cin >> p;
            p--;
            a[p] = !a[p];
            tree[0][p].first = -tree[0][p].first;
            tree[0][p].second = -tree[0][p].second;
            for(int j = 1;j <= log2(n);j++){
                p = p / 2;
                /*int f = tree[j - 1][p * 2].first;
                int s = tree[j - 1][p * 2 + 1].second;
                if(f < 0)f += (tree[j - 1][p * 2 + 1].first < 0 ? tree[j - 1][p * 2 + 1].first : 0);
                else f += tree[j - 1][p * 2 + 1].first;
                if(s < 0)s += (tree[j - 1][p * 2].second < 0 ? tree[j - 1][p * 2].second : 0);
                else s += tree[j - 1][p * 2].second;
                tree[j][p].first = f;
                tree[j][p].second = s;*/
                tree[j][p] = uni(tree[j - 1][p * 2], tree[j - 1][p * 2 + 1]);
            }
            /*for(int i = 0;i <= log2(n);i++){
                for(int j = 0;j < floor(n / pow(2, i));j++){
                    for(int q = 0;q < pow(2, i) - 1;q++)cout << "       ";
                    cout << " (" << tree[i][j].first << " " << tree[i][j].second << ") ";
                }
                cout << endl;
            }*/
        }
        if(aNum == 2){
            int l, r;
            cin >> l >> r;
            l--;
            cout << r - l - (r + 1) % 2 - (l) % 2;
            /*int l_ = l;
            pair<int, int> re;
            re.first = 0;
            re.second = 0;
            while(l < r){
                int p = 0;
                while(l % (int)pow(2, p) == 0&&l + pow(2, p) <= r)p++;
                p--;
                re = uni(re, tree[p][l / pow(2, p)]);
                l += pow(2, p);
            }*/
            //cout << re.first << " " << re.second << " >>" << r << " " << l << " >> ";
            //cout << r - l_ + min(re.first < 0 ? re.first : 0, re.second < 0 ? re.second : 0) << endl;
        }
    }
    
}
