#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define vll vector<ll>
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define fr first
#define se second
#define pb push_back
#define vvll vector<vll>
#define pll pair<ll, ll>
#define vbool vector<bool>
#define INF 10000000000000000

using namespace std;
using namespace __gnu_pbds;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n, q;
    cin >> n >> q;
    vll a(n);

    for (int i = 0; i < n; i ++) {
        cin >> a[i];
    }

    while (q --) {
        ll x, l, r;
        cin >> x;
        if (x == 1){
            cin >> l;
            l --;
            a[l] *= -1;
        }
        else {
            cin >> l >> r;
            l --;
            r --;
            vbool us(n, 0);
            ll x = -1;
            for (int i = l; i <= r; i ++) {
                if (a[i] == 1) {
                    us[i] = 1;
                    x = i;
                }
            }
            for (int i = l; i <= r; i ++) {
                if (a[i] == 1) continue;
                if (i > x) break;
                ll k = 0, minl = INF;
                for (int j = r; j >= l; j --) {
                    if (us[j]) k += a[j];
                    if (j < i) minl = min(minl, k);
                }
                k = 0;
                for (int j = 0; j < i; j ++) {
                    if (us[j]) k += a[j];

                }
                minl = min(minl, k);
                bool q = 0;
                for (int j = r; j > i; j --) {
                    if (a[j] == 1) {
                        q = 1;
                        break;
                    }
                }

                if (minl > 0 && q) {
                    us[i] = 1;
                }
                //cout << minl << ' ' << q << endl;
            }

            ll res = 0;
            for (int i = l; i <= r; i ++) {
                //cout << us[i];
                if (us[i]) res ++;
            }
            //cout << endl;

            cout << res << endl;
        }
    }



}