import java.io.PrintWriter import java.util.* fun PrintWriter.solve() { val scan = FastScanner() val n = scan.nextInt() val q = scan.nextInt() val a = LongArray(n) { scan.nextLong() } for (i in 1 until n) a[i] += a[i - 1] //BIT setup val dat = IntArray(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 = scan.nextInt() val l = scan.nextInt() val r = scan.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() } private class FastScanner { private val printable = 33..126 val `in` = System.`in` val buffer = ByteArray(65536) var ptr = 0 var buflen = 0 fun hasNextByte(): Boolean { if (ptr < buflen) { return true } else { ptr = 0 buflen = `in`.read(buffer) if (buflen <= 0) { return false } } return true } fun readByte(): Byte { return if (hasNextByte()) buffer[ptr++] else return -1 } fun hasNext(): Boolean { while (hasNextByte() && buffer[ptr] !in printable) ptr++ return hasNextByte() } fun next(): String { val sb = StringBuilder() var b = readByte() while (b in printable) { sb.appendCodePoint(b.toInt()) b = readByte() } return sb.toString() } fun nextInt(): Int { var n = 0 var b = readByte() while (b < '0'.toByte() || b > '9'.toByte()) b = readByte() while ('0'.toByte() <= b && b <= '9'.toByte()) { n *= 10 n += b - '0'.toByte() b = readByte() } return n } fun nextLong(): Long { var n = 0L var b = readByte() while (b < '0'.toByte() || b > '9'.toByte()) b = readByte() while ('0'.toByte() <= b && b <= '9'.toByte()) { n *= 10 n += b - '0'.toByte() b = readByte() } return n } fun nextDouble(): Double { return next().toDouble() } }