#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;

bool g1 = true;

void func1(vector<int>& A, int i)
{
    A[i] = -A[i];
    g1 = false;
}

int func2(vector<int>& A, int l, int r)
{
    int res = r-l+1;
    if (g1)
    {
        if (A[l] == -1) res--;
        if (A[r] == -1) res--;
        return max(res, 0);
    }

    int c = 0;

    set<int> del;

    for (int i=l; i<=r; i++)
    {
        if (A[i] == -1)
        {
            if (c > 0)
                c--;
            else
            {
                del.insert(i);
                res--;
            }
        }
        else
            c++;
    }

    c = 0;
    for (int i=r; i>=l; i--)
    {
        if (A[i] == -1)
        {
            if (del.find(i) == del.end())
            {
                if (c > 0) c--;
                else
                {
                    res--;
                }
            }
        }
        else
        {
            c++;
        }
    }

    return res;
}

int main()
{
    int n, q;
    cin >> n >> q;

    vector<int> A(n+1);
    for (int i=1; i<=n; i++)
    {
        cin >> A[i];
        if ((i%2 == 0 && A[i] != 1) ||
            (i%2 == 1 && A[i] != -1))
        {
            g1 = false;
        }
    }

    int type, p, l, r;
    for (int w=0; w<q; w++)
    {
        cin >> type;
        if (type == 1)
        {
            cin >> p;
            func1(A, p);
        }
        else
        {
            cin >> l >> r;
            cout << func2(A, l, r) << endl;
        }
    }
}