結果
問題 | No.1067 #いろいろな色 / Red and Blue and more various colors (Middle) |
ユーザー | yakamoto |
提出日時 | 2020-06-05 17:42:22 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 1,064 ms / 2,000 ms |
コード長 | 3,579 bytes |
コンパイル時間 | 17,895 ms |
コンパイル使用メモリ | 462,184 KB |
実行使用メモリ | 194,404 KB |
最終ジャッジ日時 | 2024-12-16 04:15:33 |
合計ジャッジ時間 | 33,054 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 302 ms
53,372 KB |
testcase_01 | AC | 311 ms
53,504 KB |
testcase_02 | AC | 312 ms
53,620 KB |
testcase_03 | AC | 302 ms
53,532 KB |
testcase_04 | AC | 309 ms
53,532 KB |
testcase_05 | AC | 314 ms
53,312 KB |
testcase_06 | AC | 309 ms
53,336 KB |
testcase_07 | AC | 312 ms
53,280 KB |
testcase_08 | AC | 301 ms
53,324 KB |
testcase_09 | AC | 307 ms
53,528 KB |
testcase_10 | AC | 310 ms
53,264 KB |
testcase_11 | AC | 808 ms
147,644 KB |
testcase_12 | AC | 689 ms
108,224 KB |
testcase_13 | AC | 886 ms
182,544 KB |
testcase_14 | AC | 650 ms
147,348 KB |
testcase_15 | AC | 598 ms
106,980 KB |
testcase_16 | AC | 582 ms
77,060 KB |
testcase_17 | AC | 422 ms
58,612 KB |
testcase_18 | AC | 747 ms
147,304 KB |
testcase_19 | AC | 638 ms
147,204 KB |
testcase_20 | AC | 636 ms
108,096 KB |
testcase_21 | AC | 1,050 ms
194,216 KB |
testcase_22 | AC | 1,064 ms
194,404 KB |
testcase_23 | AC | 1,045 ms
194,312 KB |
testcase_24 | AC | 309 ms
53,456 KB |
testcase_25 | AC | 305 ms
53,324 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() }