import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) class fenwick_tree(object): def __init__(self, n): self.n = n self.log = n.bit_length() self.data = [0] * n self.raw = [0] * n def show(self): res = [self.__sum(i+1) for i in range(self.n)] print("show", *res) def __sum(self, r): s = 0 while r > 0: s += self.data[r - 1] r -= r & -r return s def add(self, p, x): """ a[p] += xを行う""" self.raw[p] += x p += 1 while p <= self.n: self.data[p - 1] += x p += p & -p def sum(self, l, r): """a[l] + a[l+1] + .. + a[r-1]を返す""" return self.__sum(r) - self.__sum(l) def lower_bound(self, x): """a[0] + a[1] + .. a[i] >= x となる最小のiを返す""" if x <= 0: return -1 i = 0 k = 1 << self.log while k: if i + k <= self.n and self.data[i + k - 1] < x: x -= self.data[i + k - 1] i += k k >>= 1 return i N, Q = map(int, input().split()) A = list(map(int, input().split())) query = tuple(tuple(map(int, input().split())) for _ in range(Q)) train = fenwick_tree(N) score = fenwick_tree(N) for i in range(N): train.add(i, 1) for i, a in enumerate(A): score.add(i, a) for flag, x in query: if flag == 1: if train.raw[x] == 1: train.add(x, -1) elif flag == 2: if train.raw[x] == 0: train.add(x, 1) elif flag == 3: score.add(x - 1, 1) else: t = train.sum(0, x) l = train.lower_bound(t) r = train.lower_bound(t + 1) print(score.sum(l, r))