結果
問題 | No.1067 #いろいろな色 / Red and Blue and more various colors (Middle) |
ユーザー | yakamoto |
提出日時 | 2020-06-05 17:42:22 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 1,015 ms / 2,000 ms |
コード長 | 3,579 bytes |
コンパイル時間 | 17,052 ms |
コンパイル使用メモリ | 440,248 KB |
実行使用メモリ | 234,112 KB |
最終ジャッジ日時 | 2023-08-22 08:39:47 |
合計ジャッジ時間 | 31,583 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 276 ms
53,968 KB |
testcase_01 | AC | 284 ms
53,972 KB |
testcase_02 | AC | 282 ms
53,944 KB |
testcase_03 | AC | 277 ms
53,788 KB |
testcase_04 | AC | 283 ms
53,684 KB |
testcase_05 | AC | 282 ms
54,008 KB |
testcase_06 | AC | 277 ms
53,664 KB |
testcase_07 | AC | 280 ms
53,884 KB |
testcase_08 | AC | 281 ms
53,936 KB |
testcase_09 | AC | 278 ms
53,884 KB |
testcase_10 | AC | 280 ms
54,016 KB |
testcase_11 | AC | 711 ms
138,844 KB |
testcase_12 | AC | 651 ms
109,276 KB |
testcase_13 | AC | 812 ms
192,992 KB |
testcase_14 | AC | 579 ms
128,188 KB |
testcase_15 | AC | 541 ms
81,220 KB |
testcase_16 | AC | 523 ms
74,412 KB |
testcase_17 | AC | 393 ms
57,604 KB |
testcase_18 | AC | 651 ms
128,712 KB |
testcase_19 | AC | 567 ms
128,888 KB |
testcase_20 | AC | 566 ms
83,072 KB |
testcase_21 | AC | 1,000 ms
234,060 KB |
testcase_22 | AC | 1,015 ms
234,112 KB |
testcase_23 | AC | 1,011 ms
234,104 KB |
testcase_24 | AC | 277 ms
53,736 KB |
testcase_25 | AC | 274 ms
53,700 KB |
ソースコード
import java.io.BufferedReader import java.io.InputStream import java.io.InputStreamReader import java.util.* import kotlin.math.abs import kotlin.math.max import kotlin.math.min val MOD = 998244353L fun lowerBound(A: IntArray, s: Int, x: Int): Int { var l = s - 1 var h = A.size while(h - l > 1) { val m = (h + l) / 2 if (A[m] >= x) h = m else l = m } return h } class Solver(stream: InputStream, private val out: java.io.PrintWriter) { fun solve() { val N = ni() val Q = ni() val A = na(N) A.sort() val cumMul = LongArray(N + 1) cumMul[0] = 1 for (i in 0 until N) { cumMul[i + 1] = cumMul[i] * A[i] % MOD } val dp = Array(N + 1) {IntArray(N + 1)} dp[0][0] = 1 var best = LongArray(N + 1) best[0] = 1 var next = LongArray(N + 1) for (i in 0 until N) { Arrays.fill(next, 0) for (j in 0 .. N) { if (j + 1 <= N) next[j + 1] += best[j] next[j] += best[j] * (A[N - 1 - i] - 1) } for (j in 0..N) { next[j] %= MOD } for (j in 0..N) { dp[i + 1][j] = (next[j] * cumMul[N - 1 - i] % MOD).toInt() } val t = best best = next next = t } // debugDim(dp) for (q in 0 until Q) { val l = ni() val r = ni() val p = ni() var x = 0 for (a in l..r) { val cnt = lowerBound(A, 0, a) // debug{"q:$q a:$a cnt:$cnt"} x = x xor dp[N - cnt][p] } out.println(x % MOD) } } private val isDebug = try { // なんか本番でエラーでる System.getenv("MY_DEBUG") != null } catch (t: Throwable) { false } private var tokenizer: StringTokenizer? = null private val reader = BufferedReader(InputStreamReader(stream), 32768) 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 map(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 map(n: Int, f: (Int) -> Int): IntArray { val res = IntArray(n) for (i in 0 until n) { res[i] = f(i) } return res } private inline fun debug(msg: () -> String) { if (isDebug) System.err.println(msg()) } private fun debug(a: LongArray) { debug { a.joinToString(" ") } } private fun debug(a: IntArray) { debug { a.joinToString(" ") } } private fun debug(a: BooleanArray) { debug { a.map { if (it) 1 else 0 }.joinToString("") } } private fun debugDim(A: Array<LongArray>) { if (isDebug) { for (a in A) { debug(a) } } } private fun debugDim(A: Array<IntArray>) { if (isDebug) { for (a in A) { debug(a) } } } /** * 勝手にimport消されるのを防ぎたい */ private fun hoge() { min(1, 2) max(1, 2) abs(-10) } } fun main() { val out = java.io.PrintWriter(System.out) Solver(System.`in`, out).solve() out.flush() }