import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def FI(): return float(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def MF(): return map(float, sys.stdin.buffer.readline().split()) def MI1(): return map(int1, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] inf = 10**16 md = 998244353 # md = 10**9+7 class BitSum: def __init__(self, n): self.n = n+1 self.table = [0]*self.n def add(self, i, x): i += 1 while i < self.n: self.table[i] += x i += i & -i def sum(self, i): if i<0:return 0 i += 1 res = 0 while i > 0: res += self.table[i] i -= i & -i return res def pos(self, x): idx = 0 for lv in range((self.n-1).bit_length()-1, -1, -1): mid = idx+(1 << lv) if mid >= self.n: continue if self.table[mid] < x: x -= self.table[mid] idx += 1 << lv return idx # 要素が[0,10**6]のとき使える class Cset: def __init__(self, mx=10**6): self.mx = mx self.size = 0 self.bit = BitSum(self.mx+1) self.nums = [False]*(self.mx+1) def __repr__(self): return " ".join(str(self[i]) for i in range(self.size)) def insert(self, a): if a < 0 or a > self.mx or self.nums[a]: return False self.size += 1 self.bit.add(a, 1) self.nums[a] = True return True def remove(self, value): if value < 0 or value > self.mx or not self.nums[value]: return False self.size -= 1 self.bit.add(value, -1) self.nums[value] = False return True def erase(self, index): i = index if i >= self.size or i < -self.size: return False return self.remove(self[i]) def __getitem__(self, i): if i >= self.size or i < -self.size: return -1 if i < 0: i = self.size+i+1 else: i += 1 return self.bit.pos(i) def __contains__(self, item): return self.nums[item] def __len__(self): return self.size def bisect_left(self, a): if a < 0 or a > self.mx: return -1 if a == 0: return 0 return self.bit.sum(a-1) def bisect_right(self, a): if a < 0 or a > self.mx: return -1 return self.bit.sum(a) n, q = MI() aa = LI() bit = BitSum(n+1) st = Cset() st.insert(n) for i, a in enumerate(aa): bit.add(i, a) st.insert(i) for _ in range(q): t, x = MI1() if t == 0: st.remove(x+1) if t == 1: st.insert(x+1) if t == 2: bit.add(x, 1) if t == 3: i = st.bisect_right(x) l, r = st[i-1], st[i] print(bit.sum(r-1)-bit.sum(l-1))