#include <bits/stdc++.h>

using namespace std;

typedef int lli;
#define LF '\n'

vector<lli> v;

lli func(lli n,lli l,lli r){
    lli cnt = 0;
    for (int i =l;i<=r;i++)if (v[i]==1)cnt++;
    lli ans =cnt;
    lli z=cnt;
    lli curr = 0;
    lli minn =0;
    for (int i=l;i<=r;i++){
        if (v[i]==1){
            minn++;
            minn = min(minn,0);
            z--;
            curr++;
        }else{
            if (curr>0 && z+min(minn-1,-1)>=0){
                ans++;
                curr--;
                minn = min(minn-1,-1);
            }
        }
    }
    return ans;
}

void solve()
{
    lli n,q;
    cin >> n >> q;
    v.resize(n+1);
    for (int i=1;i<=n;i++)cin >> v[i];
    for (int i =1;i<=q;i++){
        lli type;
        cin >> type;
        if (type==1){
            lli ind;
            cin >> ind;
            v[ind]*=-1;
        }else {
            lli l,r;
            cin >> l >> r;
            cout << func(n,l,r) << LF;
        }
    }
}

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    solve();
}
