結果

問題 No.1441 MErGe
ユーザー first_vilfirst_vil
提出日時 2021-03-11 02:52:00
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 3,297 bytes
コンパイル時間 14,519 ms
コンパイル使用メモリ 452,540 KB
実行使用メモリ 68,516 KB
最終ジャッジ日時 2024-04-20 19:55:28
合計ジャッジ時間 34,707 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 263 ms
49,944 KB
testcase_01 WA -
testcase_02 AC 256 ms
49,800 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:107:24: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        while (b < '0'.toByte() || b > '9'.toByte()) b = readByte()
                       ^
Main.kt:107:44: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        while (b < '0'.toByte() || b > '9'.toByte()) b = readByte()
                                           ^
Main.kt:108:20: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        while ('0'.toByte() <= b && b <= '9'.toByte()) {
                   ^
Main.kt:108:46: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        while ('0'.toByte() <= b && b <= '9'.toByte()) {
                                             ^
Main.kt:110:26: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
            n += b - '0'.toByte()
                         ^
Main.kt:119:24: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        while (b < '0'.toByte() || b > '9'.toByte()) b = readByte()
                       ^
Main.kt:119:44: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        while (b < '0'.toByte() || b > '9'.toByte()) b = readByte()
                                           ^
Main.kt:120:20: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        while ('0'.toByte() <= b && b <= '9'.toByte()) {
                   ^
Main.kt:120:46: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
        while ('0'.toByte() <= b && b <= '9'.toByte()) {
             

ソースコード

diff #

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

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

    //BIT setup
    val dat = IntArray(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 = scan.nextInt()
        val l = scan.nextInt()
        val r = scan.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()
}

private class FastScanner {
    private val printable = 33..126
    val `in` = System.`in`
    val buffer = ByteArray(65536)
    var ptr = 0
    var buflen = 0
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = `in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun next(): String {
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun nextInt(): Int {
        var n = 0
        var b = readByte()
        
        while (b < '0'.toByte() || b > '9'.toByte()) b = readByte()
        while ('0'.toByte() <= b && b <= '9'.toByte()) {
            n *= 10
            n += b - '0'.toByte()
            b = readByte()
        }
        return n
    }
    fun nextLong(): Long {
        var n = 0L
        var b = readByte()
        
        while (b < '0'.toByte() || b > '9'.toByte()) b = readByte()
        while ('0'.toByte() <= b && b <= '9'.toByte()) {
            n *= 10
            n += b - '0'.toByte()
            b = readByte()
        }
        return n
    }
    fun nextDouble(): Double {
        return next().toDouble()
    }
}
0