#include <bits/stdc++.h>

using namespace std;

/*
if(used[to]) low[v]=min(low[v],tin[to])
else{
    dfs(to,v);
    low[v]=min(low[v],low[to]);

    if(low[to]>tin[v]) rebro;
}*/
#define ll long long
const ll F=1e18,N=5e5+3;
ll n,a[N];

ll suf[N],pr[N];


void change(){
    ll x;
    cin>>x;
    a[x]=-a[x];
}

void ans(){
    ll L,R,k=0;
    cin>>L>>R;
    for(ll l=L,s=0;l<=R;++l){
        s+=a[l];
        if(s<0){
            s-=a[l];
            a[l]=-3;
            k++;
        }
    }

    for(ll r=R,s=0;r>=L;--r){
        if(a[r]==-3) {a[r]=-1;continue;}

        s+=a[r];
        if(s<0){
            s-=a[r];
            k++;
        }
    }


    cout<<R-L+1-k<<"\n";
}

int main()
{
    ll q,t;
    cin>>n>>q;
    for(ll i=1;i<=n;++i) cin>>a[i];
    a[0]=-1e18;
    a[n+1]=-1e18;
    for(ll i=1;i<=n;++i){
        for(ll j=i,s=0;j>=0;--j){
            s+=a[j];
            if(s<0){
                suf[i]=j;
                break;
            }
        }


        for(ll j=i,s=0;j<=n+1;++j){
            s+=a[j];
            if(s<0){
                pr[i]=j;
                break;
            }
        }
    }



    while(q--){
        cin>>t;

        if(t==1) change();
        else ans();
    }
}
