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 class Solver(stream: InputStream, private val out: java.io.PrintWriter) { private val reader = BufferedReader(InputStreamReader(stream), 32768) private val NN = ni() private val M = ni() private val Q = ni() fun solve() { val zero = IntArray(NN) { it } val tree = SegmentTreeA(M, zero) for (q in 0 until Q) { val type = ni() when (type) { 1 -> { val d = ni() - 1 val p = na(NN, -1) tree.update(d, p) } 2 -> { val s = ni() val p = tree.query(0, s) debug { "type2 ${p.joinToString(" ")}" } val inv = IntArray(NN) for (i in 0 until NN) { inv[p[i]] = i } out.println(inv.map { it + 1 }.joinToString(" ")) } else -> { val (l, r) = na(2, -1) val p = tree.query(l, r + 1) debug { "type3 ${p.joinToString(" ")}" } var ans = 0L for (i in 0 until NN) { ans += abs(i - p[i]) } out.println(ans) } } } } private inline fun fx(a: IntArray, b: IntArray) = run { val res = IntArray(NN) for (i in res.indices) { res[i] = b[a[i]] } res } inner class SegmentTreeA(val n: Int, val zero: IntArray) { private inline fun ap(x: IntArray, m: IntArray) = m // 入れ替え private val N = if (Integer.highestOneBit(n) == n) n else Integer.highestOneBit(n) shl 1 private val dat = Array(2*N){zero} fun update(i: Int, a: IntArray) { var ix = i + N dat[ix] = ap(dat[ix], a) while(ix > 1) { dat[ix shr 1] = if (ix and 1 == 0) fx(dat[ix], dat[ix xor 1]) else fx(dat[ix xor 1], dat[ix]) ix = ix shr 1 } } /** * [a, b) */ fun query(a: Int, b: Int, l: Int = 0, r: Int = N, k: Int = 1): IntArray { var resL = zero var resR = zero var left = a + N var right = b - 1 + N while(left <= right) { if ((left and 1) == 1) resL = fx(resL, dat[left]) if ((right and 1) == 0) resR = fx(dat[right], resR) left = (left + 1) shr 1 // 右の子供なら右の親に移動 right = (right - 1) shr 1 // 左の子供なら左の親に移動 } return fx(resL, resR) } fun get(i: Int) = dat[N + i] override fun toString() = "[${(0 until n).map{get(it)}.joinToString(" ")}]" } 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()) } /** * コーナーケースでエラー出たりするので、debug(dp[1])のように添え字付きの場合はdebug{}をつかうこと */ 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()} private inline fun assert(b: Boolean, f: () -> String) = run{if (!b) throw AssertionError(f())} } fun main() { val out = java.io.PrintWriter(System.out) Solver(System.`in`, out).solve() out.flush() }