#include <bits/stdc++.h>
using namespace std;

int main() {
    #define ll long long

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.tie(NULL);
    
    int n,q,type,p,l,r,len;
    cin >> n >> q;
    int a[n];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    for(int Q = 0; Q < q; Q++)
    {
        cin >> type;
        if(type == 1)
        {
            cin >> p;
            a[p-1] = 0 - a[p-1];
        }
        else
        {
            cin >> l >> r;
            len = r-l+1;

            for(int i = l-1; i < r; i++)
            {
                if(a[i] == -1)
                {
                    l++;
                    len--;
                }
                else
                {
                    break;
                }
            }
            for(int i = r-1; i >= l-1; i--)
            {
                if(a[i] == -1)
                {
                    r--;
                    len--;
                }
                else
                {
                    break;
                }
            }

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