import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.BitSet;
import java.util.StringTokenizer;

public class Task4 {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken());
            int q = Integer.parseInt(st.nextToken());
            BitSet a = new BitSet(n);
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < n;i++) {
                if(Integer.parseInt(st.nextToken()) == 1) {
                    a.set(i);
                }
            }
            for (int i = 0; i < q; i++) {
                st = new StringTokenizer(br.readLine());
                int mode = Integer.parseInt(st.nextToken());
                if(mode == 1) {
                    int p = Integer.parseInt(st.nextToken());
                    a.flip(p);
                } else {
                    int l = Integer.parseInt(st.nextToken());
                    int r = Integer.parseInt(st.nextToken());
                    System.out.println(calc(a, l, r));
                }
            }
//          Arrays.stream(a).forEach(arr -> System.out.println(Arrays.toString(arr)));
        } catch (IOException ex) {
        }
    }

    private static int calc(BitSet a, int l, int r) {
        return r - l + 1 - (a.get(l - 1) ? 0 : 1) - (a.get(r - 1) ? 0 : 1);
    }
}
