class BIT: def __init__(self, n): self.n = n self.bit = [0]*(self.n+1) # 1-indexed def init(self, init_val): for i, v in enumerate(init_val): self.add(i, v) def add(self, i, x): # i: 0-indexed i += 1 # to 1-indexed while i <= self.n: self.bit[i] += x i += (i & -i) def sum(self, i, j): # return sum of [i, j) # i, j: 0-indexed return self._sum(j) - self._sum(i) def _sum(self, i): # return sum of [0, i) # i: 0-indexed res = 0 while i > 0: res += self.bit[i] i -= i & (-i) return res def lower_bound(self, x): s = 0 pos = 0 depth = self.n.bit_length() v = 1 << depth for i in range(depth, -1, -1): k = pos + v if k <= self.n and s + self.bit[k] < x: s += self.bit[k] pos += v v >>= 1 return pos import sys input = sys.stdin.buffer.readline n, q = map(int, input().split()) A = list(map(int, input().split())) bit1 = BIT(n+1) bit1.init([1]*(n+1)) bit2 = BIT(n+1) bit2.init(A) for i in range(q): t, x = map(int, input().split()) x -= 1 if t == 1: if bit1.sum(x+1, x+2): bit1.add(x+1, -1) elif t == 2: if bit1.sum(x+1, x+2) == 0: bit1.add(x+1, 1) elif t == 3: bit2.add(x, 1) else: s = bit1.sum(0, x+1) l = bit1.lower_bound(s) r = bit1.lower_bound(s+1) print(bit2.sum(l, r))