# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
886039 | CDuong | Sum Zero (RMI20_sumzero) | Kotlin (JVM) | 515 ms | 31984 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
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(9) { 1 }
while (i < 9) {
cope[i] = cope[i - 1] * 5
i++
}
var nxt = Array(9) { 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 < 9) {
j = 0
while (j < n) {
nxt[i][j] = nxt[i - 1][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 = 8
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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |