import sys import itertools input = sys.stdin.buffer.readline class Bit: """https://ikatakos.com/pot/programming_algorithm/data_structure/binary_indexed_tree から拝借しています。""" def __init__(self, n): self.size = n self.tree = [0] * (n + 1) self.depth = n.bit_length() def __getitem__(self, item): return self.sum(item) - self.sum(item - 1) def initialize(self, A): for i, a in enumerate(A, 1): self.tree[i] = a j = (i & -i) >> 1 while j: self.tree[i] += self.tree[i - j] j >>= 1 def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def lower_bound(self, x): """ 累積和がx以上になる最小のindexと、その直前までの累積和 """ sum_ = 0 pos = 0 for i in range(self.depth, -1, -1): k = pos + (1 << i) if k <= self.size and sum_ + self.tree[k] < x: sum_ += self.tree[k] pos += 1 << i return pos + 1 N, Q = map(int, input().split()) A = tuple(map(int, input().split())) As = [0] + list(itertools.accumulate(A)) bit = Bit(N) bit.initialize([1] * N) for _ in range(Q): t, l, r = map(int, input().split()) if t == 1: indices = [] for i in range(l, r): indices.append(bit.lower_bound(i)) for idx in indices: bit.add(idx + 1, -1) else: assert t == 2 lidx = bit.lower_bound(l) ridx = bit.lower_bound(r) print(As[ridx] - As[lidx - 1])