import java.io.BufferedReader import java.io.InputStream import java.io.InputStreamReader import java.lang.AssertionError import java.util.* import kotlin.math.abs import kotlin.math.max import kotlin.math.min val MOD = 1_000_000_007 /** * @param merge ツリーを↑に上がっていくときのマージ関数 todo merge(a, a) = a でない場合要素数いるんじゃない? * @param plus addでノードを更新する関数 (昔の値, 要素数, 引数) */ class DelayMergeTree2(n: Int, val mZero: Long, val merge: (Long, Long) -> Long, val pZero: Long, val plus: (Long, Int, Long) -> Long) { private val N = if (Integer.highestOneBit(n) == n) n else Integer.highestOneBit(n) shl 1 private val value = LongArray(N * 2){mZero} private val delay = LongArray(N * 2){pZero} private val elms = IntArray(N * 2) init { elms[1] = N for (i in 1 until N) { elms[2 * i] = elms[i] / 2 elms[2 * i + 1] = elms[i] / 2 } } private inline fun push(k: Int) { if (k < N && delay[k] != pZero) { value[k * 2] = plus(value[k * 2], elms[k * 2], delay[k]) value[k * 2 + 1] = plus(value[k * 2 + 1], elms[k * 2 + 1], delay[k]) delay[k * 2] = plus(delay[k * 2], elms[k * 2], delay[k]) delay[k * 2 + 1] = plus(delay[k * 2 + 1], elms[k * 2 + 1], delay[k]) delay[k] = pZero } } /** * [a, b) */ fun add(a: Int, b: Int, x: Long, k: Int = 1, l: Int = 0, r: Int = N) { if (a >= r || l >= b) return // ノードが範囲からはずれてる if (a <= l && r <= b) { // ノードが完全に範囲に含まれる value[k] = plus(value[k], elms[k], x) delay[k] = plus(delay[k], elms[k], x) return } push(k) val m = (l + r) / 2 val lft = k * 2 val rgt = lft + 1 add(a, b, x, lft, l, m) add(a, b, x, rgt, m, r) value[k] = merge(value[lft], value[rgt]) } /** * [a, b) */ fun query(a: Int, b: Int, k: Int = 1, l: Int = 0, r: Int = N): Long { if (a >= r || l >= b) return mZero // ノードが範囲からはずれてる if (a <= l && r <= b) { // ノードが完全に範囲に含まれる return value[k] } push(k) val m = (l + r) / 2 val lft = k * 2 val rgt = lft + 1 return merge(query(a, b, lft, l, m), query(a, b, rgt, m, r)) } fun eval(i: Int): Long { _eval(N + i) return value[N + i] } fun inspect() = run { Pair(value, delay) } fun _eval(k: Int) { if (k > 1) { _eval(k / 2) } push(k) } } class Solver(stream: InputStream, private val out: java.io.PrintWriter) { private val reader = BufferedReader(InputStreamReader(stream), 32768) private val N = ni() private val INF = 1e18.toLong() private fun plus(a: Long, num: Int, b: Long) = run { if (a == INF) b else a + b } private val tree = DelayMergeTree2(N, INF, ::min, 0, ::plus) fun solve() { for (i in 0 until N) { tree.add(i, i + 1, nl()) } for (q in 0 until ni()) { val type = ni() val l = ni() - 1 val r = ni() - 1 val c = nl() when(type) { 1 -> { tree.add(l, r + 1, c) } else -> { out.println(tree.query(l, r + 1)) } } } } private val isDebug = try { // なんか本番でエラーでる System.getenv("MY_DEBUG") != null } catch (t: Throwable) { false } private var tokenizer: StringTokenizer? = null private fun next(): String { while (tokenizer == null || !tokenizer!!.hasMoreTokens()) { tokenizer = StringTokenizer(reader.readLine()) } return tokenizer!!.nextToken() } private fun ni() = next().toInt() private fun nl() = next().toLong() private fun ns() = next() private fun na(n: Int, offset: Int = 0): IntArray { return IntArray(n) { ni() + offset } } private fun nal(n: Int, offset: Int = 0): LongArray { val res = LongArray(n) for (i in 0 until n) { res[i] = nl() + offset } return res } private fun na2(n: Int, offset: Int = 0): Array { val a = Array(2){IntArray(n)} for (i in 0 until n) { for (e in a) { e[i] = ni() + offset } } return a } private inline fun debug(msg: () -> String) { if (isDebug) System.err.println(msg()) } private inline fun debug(a: LongArray) { debug { a.joinToString(" ") } } private inline fun debug(a: IntArray) { debug { a.joinToString(" ") } } private inline fun debug(a: BooleanArray) { debug { toString(a) } } private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString("")} private inline fun debugDim(A: Array) { if (isDebug) { for (a in A) { debug(a) } } } private inline fun debugDim(A: Array) { if (isDebug) { for (a in A) { debug(a) } } } private inline fun debugDim(A: Array) { if (isDebug) { for (a in A) { debug(a) } } } /** * 勝手にimport消されるのを防ぎたい */ private fun hoge() { min(1, 2) max(1, 2) abs(-10) } private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()} } fun main() { val out = java.io.PrintWriter(System.out) Solver(System.`in`, out).solve() out.flush() }