import sys def LI(): return list(map(int, sys.stdin.readline().split())) 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): i += 1 res = 0 while i > 0: res += self.table[i] i -= i & -i return res def rank(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 def main(): n, q = LI() aa = LI() cs = [0] for a in aa: cs.append(cs[-1]+a) bit = BitSum(n) for i in range(1, n): bit.add(i, 1) lr = list(range(n)) for _ in range(q): t, l, r = LI() l -= 1 if t == 1: i = bit.rank(l) for _ in range(r-l-1): j = lr[i]+1 bit.add(j, -1) k = lr[j] lr[k] = i lr[i] = k else: i = bit.rank(l) j = bit.rank(r) print(cs[j]-cs[i]) main()