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

#define int long long
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fst first
#define snd second
#define ff first
#define st second
#define endl "\n"
#define len(x) x.size()

void I_LOVE_PEREKOPSKA() {
    int n, q;
    cin>>n>>q;
    vector<int> a(n);
    for (auto &x:a)
        cin>>x;
    auto krasa = [&](int l, int r) {
        vector<int> d = a;
        l--; r--;
        int ans = 0;
        int nl = l;
        int nr = r;
        for (int i=nl;i<nr;i++)
            if (d[i]==-1) l=i;
            else break;
        for (int i=nr;i>=nl;i--)
            if (d[i]==-1) r = i-1; else break;
        // cout<<l<<" "<<r<<endl;
        int s = 0;
        for (int i=l;i<=r;i++)
            if (s+d[i]<0) {d[i] = 0;} else s += d[i];
        for (int i=l;i<=r;i++) {
            if (d[i]!=0) ans++;
        }
        return ans;
    };
    while (q--) {
        int t;
        cin>>t;
        if (t==1) {
            int p;
            cin>>p;
            a[p-1] = -a[p-1];
        }
        if (t==2) {
            int l,r;
            cin>>l>>r;
            cout<<krasa(l, r)<<endl;
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int t = 1;
    // cin>>t;
    while (t--) {
        I_LOVE_PEREKOPSKA();
    }
}