import sys

n, q = map(int, sys.stdin.readline().split())
array = list(map(int, sys.stdin.readline().split()))
tree = [0] * 4 * n

def build(x, lx, rx):
    if lx == rx - 1:
        tree[x] = 1 if array[lx] else -1
        return

    mx = (rx + lx) // 2
    build(x*2+1, lx, mx)
    build(x*2+2, mx, rx)

    tree[x] = max(tree[x*2+1], tree[x*2+2], tree[x*2+1] + tree[x*2+2], 0)

def update(index, x, lx, rx):
    if index < lx or index >= rx:
        return
    
    if lx == rx - 1 == index:
        tree[x] = -1 if tree[x] else 1
        return 
    
    mx = (rx + lx) // 2
    update(index, x*2+1, lx, mx)
    update(index, x*2+2, mx, rx)
    tree[x] = max(tree[x*2+1], tree[x*2+2], tree[x*2+1] + tree[x*2+2], 0)

def count(l, r, x, lx, rx):
    if l >= rx or r <= lx:
        return 0
    if l <= lx and r >= rx:
        return tree[x]
    
    mx = (rx + lx) // 2
    return count(l, r, x*2+1, lx, mx) + count(l, r, x*2+2, mx, rx)

build(0, 0, n)


for _ in range(q):
    temp = list(sys.stdin.readline().split())
    if temp[0] == '1':
        p = int(temp[1])
        update(p, 0, 0, n)
    else: # == '2'
        l = int(temp[1])
        r = int(temp[2])
        print(count(l-1, r, 0, 0, n))