import java.io.PrintWriter import java.util.* fun PrintWriter.solve() { val n = nextInt() val q = nextInt() val a = LongArray(n) { nextLong() } for (i in 1 until n) a[i] += a[i - 1] //BIT setup val dat = Array(n + 1) { 1 } for (i in 1..n) if (i + (i and -i) <= n) dat[i + (i and -i)] += dat[i] var n2 = 1 while (n2 * 2 <= n) n2 *= 2 repeat(q) { val t = nextInt() val l = nextInt() val r = nextInt() if (t == 1) { repeat(r - l) { var j = 0 var x = l + 1 var k = n2 while (0 < k) { if (j + k <= n && x > dat[j + k]) { x -= dat[j + k] j += k } k /= 2 } ++j while (j <= n) { --dat[j] j += j and -j } } } else { var L = 0 var R = 0 var x = l var y = r + 1 var k = n2 while (0 < k) { if (L + k <= n && x > dat[L + k]) { x -= dat[L + k] L += k } if (R + k <= n && y > dat[R + k]) { y -= dat[R + k] R += k } k /= 2 } println(a[R - 1] - if (0 < L) a[L - 1] else { 0L }) } } } fun main() { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine()!! fun nextDouble() = next().toDouble() // endregion