import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int q = sc.nextInt(); BinaryIndexedTree bit = new BinaryIndexedTree(n + 1); for (int i = 1; i <= n; i++) { bit.add(i, sc.nextInt()); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int type = sc.nextInt(); int idx = sc.nextInt(); if (type == 1) { bit.connect(idx); } else if (type == 2) { bit.separate(idx); } else if (type == 3) { bit.add(idx, 1); } else { sb.append(bit.getValue(idx)).append("\n"); } } System.out.print(sb); } } class BinaryIndexedTree { int size; long[] tree; int[] group; public BinaryIndexedTree(int size) { this.size = size; tree = new long[size]; group = new int[size]; for (int i = 1; i < size; i++) { addGroup(i, 1); } } public void add(int idx, long value) { int mask = 1; while (idx < size) { if ((idx & mask) != 0) { tree[idx] += value; idx += mask; } mask <<= 1; } } public void connect(int idx) { if (getGroupSum(idx) < getGroupSum(idx + 1)) { addGroup(idx + 1, -1); } } public void separate(int idx) { if (getGroupSum(idx) == getGroupSum(idx + 1)) { addGroup(idx + 1, 1); } } public void addGroup(int idx, int value) { int mask = 1; while (idx < size) { if ((idx & mask) != 0) { group[idx] += value; idx += mask; } mask <<= 1; } } public long getSum(int from, int to) { return getSum(to) - getSum(from); } public long getSum(int x) { int mask = 1; long ans = 0; while (x > 0) { if ((x & mask) != 0) { ans += tree[x]; x -= mask; } mask <<= 1; } return ans; } public int getGroupSum(int x) { int mask = 1; int ans = 0; while (x > 0) { if ((x & mask) != 0) { ans += group[x]; x -= mask; } mask <<= 1; } return ans; } public long getValue(int idx) { int leftMin = 0; int rightMin = idx; while (rightMin - leftMin > 1) { int m = (leftMin + rightMin) / 2; if (getGroupSum(m) < getGroupSum(idx)) { leftMin = m; } else { rightMin = m; } } int leftMax = idx; int rightMax = size; while (rightMax - leftMax > 1) { int m = (leftMax + rightMax) / 2; if (getGroupSum(m) == getGroupSum(idx)) { leftMax = m; } else { rightMax = m; } } return getSum(leftMin, leftMax); } }