結果
問題 | No.1000 Point Add and Array Add |
ユーザー | yakamoto |
提出日時 | 2020-03-10 15:20:27 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 1,068 ms / 2,000 ms |
コード長 | 3,586 bytes |
コンパイル時間 | 17,706 ms |
コンパイル使用メモリ | 469,748 KB |
実行使用メモリ | 105,688 KB |
最終ジャッジ日時 | 2024-11-15 23:16:48 |
合計ジャッジ時間 | 32,685 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 321 ms
57,884 KB |
testcase_01 | AC | 302 ms
57,620 KB |
testcase_02 | AC | 313 ms
57,904 KB |
testcase_03 | AC | 310 ms
57,796 KB |
testcase_04 | AC | 313 ms
57,720 KB |
testcase_05 | AC | 318 ms
57,796 KB |
testcase_06 | AC | 310 ms
57,808 KB |
testcase_07 | AC | 309 ms
57,616 KB |
testcase_08 | AC | 303 ms
57,812 KB |
testcase_09 | AC | 300 ms
57,724 KB |
testcase_10 | AC | 304 ms
57,816 KB |
testcase_11 | AC | 304 ms
57,728 KB |
testcase_12 | AC | 404 ms
62,120 KB |
testcase_13 | AC | 388 ms
61,940 KB |
testcase_14 | AC | 438 ms
62,668 KB |
testcase_15 | AC | 427 ms
62,248 KB |
testcase_16 | AC | 938 ms
102,068 KB |
testcase_17 | AC | 883 ms
100,984 KB |
testcase_18 | AC | 1,068 ms
104,524 KB |
testcase_19 | AC | 1,063 ms
103,840 KB |
testcase_20 | AC | 927 ms
94,696 KB |
testcase_21 | AC | 1,047 ms
105,276 KB |
testcase_22 | AC | 1,036 ms
105,688 KB |
testcase_23 | AC | 1,023 ms
105,468 KB |
コンパイルメッセージ
Main.kt:146:27: warning: parameter 'offset' is never used private fun nal(n: Int, offset: Int = 0): LongArray { ^
ソースコード
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 = 1_000_000_007 class RangeUpdateTree(n: Int, private val zero: Long, private val f: (Long, Long) -> Long) { private val N = if (Integer.highestOneBit(n) == n) n else Integer.highestOneBit(n) shl 1 private val dat = LongArray(2 * N){zero} /** * [l, r) */ fun add(l: Int, r: Int, a: Long) { var left = l + N var right = r - 1 + N while(left <= right) { if ((left and 1) == 1) dat[left] = f(dat[left], a) if ((right and 1) == 0) dat[right] = f(dat[right], a) left = (left + 1) shr 1 // 右の子供なら右の親に移動 right = (right - 1) shr 1 // 左の子供なら左の親に移動 } } fun query(i: Int): Long { var ix = N + i var res: Long = zero while(ix >= 1) { res = f(res, dat[ix]) ix = ix shr 1 } return res } } data class Query(val isA: Boolean, val x: Int, val y: Int) class Solver(stream: InputStream, private val out: java.io.PrintWriter) { fun solve() { val N = ni() val Q = ni() val A = na(N) val queries = Array(Q) { Query(ns() == "A", ni(), ni()) } val ans = LongArray(N) val tree = RangeUpdateTree(N, 0, Long::plus) for (i in Q -1 downTo 0) { if (queries[i].isA) { val ix = queries[i].x - 1 val v = queries[i].y val times = tree.query(ix) ans[ix] += times * v } else { val s = queries[i].x - 1 val t = queries[i].y tree.add(s, t, 1) } } for (i in 0 until N) { val times = tree.query(i) ans[i] += times * A[i] } out.println(ans.joinToString(" ")) } 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() } return res } 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<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() }