Submission #886036

#TimeUsernameProblemLanguageResultExecution timeMemory
886036CDuongSum Zero (RMI20_sumzero)Kotlin (JVM)
0 / 100
478 ms32336 KiB
import kotlin.math.* import java.util.Vector private fun readLn() = readLine()!! private fun readInt() = readLn().toInt() private fun readLong() = readLn().toLong() private fun readStrings() = readLn().split(" ") private fun readInts() = readStrings().map { it.toInt() } private fun readLongs() = readStrings().map { it.toLong() } fun main() { var n = readInt() var a = readInts() var i: Int = 0 i = 1 var cope = Array(10) { 1 } while (i < 10) { cope[i] = cope[i - 1] * 4 i++ } var nxt = Array(10) { Array<Int>(n + 2) { n + 1 } } var mp = mutableMapOf<Long, Int>() mp[0] = 0 i = 0 var cur_sum: Long = 0 while (i < n) { cur_sum += a[i] if (mp[cur_sum] != null) { // println(mp[cur_sum]) nxt[0][mp[cur_sum]!!] = i + 1 } mp[cur_sum] = i + 1; i++; } i = n; while (i >= 0) { nxt[0][i] = min(nxt[0][i], nxt[0][i + 1]) i-- } i = 1 var j = 0 while (i < 10) { j = 0 while (j < n) { nxt[i][j] = nxt[i - 1][nxt[i - 1][nxt[i - 1][nxt[i - 1][j]]]] // println("${i}, ${j}, ${nxt[i][j]}") j++ } i++; } var q = readInt() repeat(q) { var (l, r) = readInts() l-- var res = 0 i = 9 while (i >= 0 && l < n) { while (nxt[i][l] <= r) { res += cope[i] l = nxt[i][l] } i-- } println(res) } // i = 0 // while (i < n) { // println(nxt[0][i]) // i++ // } }

Compilation message (stderr)

sumzero.kt:14:18: warning: variable 'i' initializer is redundant
    var i: Int = 0
                 ^
sumzero.kt:47:13: warning: variable 'j' initializer is redundant
    var j = 0
            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...