結果
問題 | No.1558 Derby Live |
ユーザー | yakamoto |
提出日時 | 2021-06-26 19:29:28 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 922 ms / 2,000 ms |
コード長 | 5,065 bytes |
コンパイル時間 | 18,139 ms |
コンパイル使用メモリ | 466,712 KB |
実行使用メモリ | 97,028 KB |
最終ジャッジ日時 | 2024-06-25 09:18:42 |
合計ジャッジ時間 | 49,265 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 699 ms
90,620 KB |
testcase_01 | AC | 922 ms
93,104 KB |
testcase_02 | AC | 286 ms
50,280 KB |
testcase_03 | AC | 799 ms
88,672 KB |
testcase_04 | AC | 599 ms
79,984 KB |
testcase_05 | AC | 598 ms
78,068 KB |
testcase_06 | AC | 722 ms
86,056 KB |
testcase_07 | AC | 419 ms
54,184 KB |
testcase_08 | AC | 691 ms
84,740 KB |
testcase_09 | AC | 704 ms
85,540 KB |
testcase_10 | AC | 730 ms
87,392 KB |
testcase_11 | AC | 745 ms
91,136 KB |
testcase_12 | AC | 769 ms
91,808 KB |
testcase_13 | AC | 777 ms
91,748 KB |
testcase_14 | AC | 788 ms
93,572 KB |
testcase_15 | AC | 818 ms
93,124 KB |
testcase_16 | AC | 823 ms
95,660 KB |
testcase_17 | AC | 861 ms
90,504 KB |
testcase_18 | AC | 878 ms
95,996 KB |
testcase_19 | AC | 902 ms
97,028 KB |
testcase_20 | AC | 897 ms
95,928 KB |
testcase_21 | AC | 855 ms
95,096 KB |
testcase_22 | AC | 867 ms
93,388 KB |
testcase_23 | AC | 897 ms
94,220 KB |
testcase_24 | AC | 876 ms
96,900 KB |
testcase_25 | AC | 884 ms
96,996 KB |
testcase_26 | AC | 865 ms
96,704 KB |
testcase_27 | AC | 850 ms
91,940 KB |
testcase_28 | AC | 865 ms
96,796 KB |
testcase_29 | AC | 892 ms
94,136 KB |
testcase_30 | AC | 859 ms
95,168 KB |
testcase_31 | AC | 900 ms
92,856 KB |
testcase_32 | AC | 916 ms
96,944 KB |
testcase_33 | AC | 318 ms
52,200 KB |
testcase_34 | AC | 316 ms
52,300 KB |
コンパイルメッセージ
Main.kt:54:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun fx(a: IntArray, b: IntArray) = run { ^ Main.kt:63:13: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun ap(x: IntArray, m: IntArray) = m // 入れ替え ^ Main.kt:63:27: warning: parameter 'x' is never used private inline fun ap(x: IntArray, m: IntArray) = m // 入れ替え ^ Main.kt:83:31: warning: parameter 'l' is never used fun query(a: Int, b: Int, l: Int = 0, r: Int = N, k: Int = 1): IntArray { ^ Main.kt:83:43: warning: parameter 'r' is never used fun query(a: Int, b: Int, l: Int = 0, r: Int = N, k: Int = 1): IntArray { ^ Main.kt:83:55: warning: parameter 'k' is never used fun query(a: Int, b: Int, l: Int = 0, r: Int = N, k: Int = 1): IntArray { ^ Main.kt:194:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun debug(a: LongArray) { ^ Main.kt:198:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun debug(a: IntArray) { ^ Main.kt:202:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun debug(a: BooleanArray) { ^ Main.kt:206:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else
ソースコード
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<IntArray> { 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<LongArray>) { if (isDebug) { for (a in A) { debug(a) } } } private inline fun debugDim(A: Array<IntArray>) { if (isDebug) { for (a in A) { debug(a) } } } private inline fun debugDim(A: Array<BooleanArray>) { 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() }