結果

問題 No.1441 MErGe
ユーザー first_vilfirst_vil
提出日時 2021-03-10 15:25:27
言語 Kotlin
(1.9.23)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,987 bytes
コンパイル時間 18,906 ms
コンパイル使用メモリ 453,872 KB
実行使用メモリ 105,348 KB
最終ジャッジ日時 2024-04-20 10:36:36
合計ジャッジ時間 47,405 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 292 ms
54,384 KB
testcase_01 AC 294 ms
54,284 KB
testcase_02 AC 277 ms
54,240 KB
testcase_03 AC 384 ms
58,376 KB
testcase_04 AC 389 ms
58,316 KB
testcase_05 AC 440 ms
57,072 KB
testcase_06 AC 454 ms
57,048 KB
testcase_07 AC 459 ms
56,908 KB
testcase_08 AC 767 ms
86,948 KB
testcase_09 AC 727 ms
83,552 KB
testcase_10 AC 980 ms
104,508 KB
testcase_11 AC 751 ms
89,824 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 982 ms
95,440 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 AC 868 ms
89,652 KB
testcase_29 AC 839 ms
92,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve() {
    val n = nextInt()
    val q = nextInt()
    val a = LongArray(n) { nextLong() }
    for (i in 1 until n) a[i] += a[i - 1]

    //BIT setup
    val dat = Array(n + 1) { 1 }
    for (i in 1..n) if (i + (i and -i) <= n) dat[i + (i and -i)] += dat[i]
    var n2 = 1
    while (n2 * 2 <= n) n2 *= 2

    repeat(q) {
        val t = nextInt()
        val l = nextInt()
        val r = nextInt()
        if (t == 1) {
            repeat(r - l) {
                var j = 0
                var x = l + 1
                var k = n2
                while (0 < k) {
                    if (j + k <= n && x > dat[j + k]) {
                        x -= dat[j + k]
                        j += k
                    }
                    k /= 2
                }
                ++j
                while (j <= n) {
                    --dat[j]
                    j += j and -j
                }
            }
        } else {
            var L = 0
            var R = 0
            var x = l
            var y = r + 1
            var k = n2
            while (0 < k) {
                if (L + k <= n && x > dat[L + k]) {
                    x -= dat[L + k]
                    L += k
                }
                if (R + k <= n && y > dat[R + k]) {
                    y -= dat[R + k]
                    R += k
                }
                k /= 2
            }
            println(a[R - 1] - if (0 < L) a[L - 1] else { 0L })
        }
    }
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve()
    writer.flush()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

fun next(): String {
    while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
    return st.nextToken()
}

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()!!
fun nextDouble() = next().toDouble()
// endregion
0