import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	class SegTree {
		int n;
		long[] v;

		public SegTree(int n_) {
			n = 1;
			while (n < n_)
				n *= 2;
			v = new long[2 * n - 1];
		}

		void add(int k, long val) {
			k += n - 1;
			v[k] += val;
			while (k > 0) {
				k = (k - 1) / 2;
				v[k] = v[2 * k + 1] + v[2 * k + 2];
			}
		}

		long sum(int a, int b) {
			return sum(0, n, a, b, 0);
		}

		long sum(int l, int r, int a, int b, int k) {
			if (a <= l && r <= b)
				return v[k];
			else if (b <= l || r <= a)
				return 0;
			else {
				long lv = sum(l, (l + r) / 2, a, b, 2 * k + 1);
				long rv = sum((l + r) / 2, r, a, b, 2 * k + 2);
				return lv + rv;
			}
		}
	}

	void run() throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		long[] A = new long[N];
		for (int i = 0; i < A.length; ++i) {
			A[i] = sc.nextLong();
		}
		SegTree seg1 = new SegTree(N);
		SegTree seg2 = new SegTree(N);
		for (int i = 0; i < N; ++i) {
			seg1.v[i + seg1.n - 1] = A[i];
		}
		for (int i = seg1.n - 2; i >= 0; --i) {
			seg1.v[i] = seg1.v[2 * i + 1] + seg1.v[2 * i + 2];
		}
		for (int i = 0; i < Q; ++i) {
			int query = sc.nextInt();
			int x = sc.nextInt();
			--x;
			if (query == 1) {
				if (seg2.sum(x, x + 1) == 0) {
					seg2.add(x, 1);
				}
			} else if (query == 2) {
				if (seg2.sum(x, x + 1) == 1) {
					seg2.add(x, -1);
				}
			} else if (query == 3) {
				seg1.add(x, 1);
			} else if (query == 4) {
				int r_ng = N;
				int r_ok = x;
				while (r_ng - r_ok > 1) {
					int m = (r_ng + r_ok) / 2;
					if (seg2.sum(x, m) < m - x) {
						r_ng = m;
					} else {
						r_ok = m;
					}
				}
				int l_ok = x;// [x, x)
				int l_ng = -1;
				while (l_ok - l_ng > 1) {
					int m = (l_ng + l_ok) / 2;
					if (seg2.sum(m, x) < x - m) {
						l_ng = m;
					} else {
						l_ok = m;
					}
				}
				System.out.println(seg1.sum(l_ok, r_ok + 1));
			}
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}