Submission #53632862
Source Code Expand
import java.io.* import java.util.* import java.util.function.IntPredicate import kotlin.collections.* val INPUT: InputStream = System.`in` val OUTPUT: PrintStream = System.out val _reader = INPUT.bufferedReader() var _tokenizer: StringTokenizer = StringTokenizer("") fun read(): String { while (!_tokenizer.hasMoreTokens()) { _tokenizer = StringTokenizer(_reader.readLine() ?: return "", " ") } return _tokenizer.nextToken() } fun readInt() = read().toInt() fun readDouble() = read().toDouble() fun readLong() = read().toLong() fun readStrings(n: Int) = List(n) { read() } fun readInts(n: Int) = List(n) { readInt() } fun readIntArray(n: Int) = IntArray(n) { readInt() } fun readDoubles(n: Int) = List(n) { readDouble() } fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() } fun readLongs(n: Int) = List(n) { readLong() } fun readLongArray(n: Int) = LongArray(n) { readLong() } val _writer = PrintWriter(OUTPUT, false) inline fun output(block: PrintWriter.() -> Unit) { _writer.apply(block).flush() } class MutableIntMap<K> : LinkedHashMap<K, Int>() { override operator fun get(key: K): Int = super.get(key) ?: 0 fun increment(key: K, value: Int = 1) { this[key] = this[key] + value } companion object { fun <K> mutableIntMapOf(vararg pairs: Pair<K, Int>) = MutableIntMap<K>().apply { putAll(pairs) } } } typealias Pii = Pair<Int, Int> fun readPii() = readInt() to readInt() fun readPiis(n: Int) = List(n) { readPii() } infix fun Int.hasBit(i: Int): Boolean = this and (1 shl i) > 0 infix fun Int.xorBit(i: Int): Int = this xor (1 shl i) infix fun Long.hasBit(i: Int): Boolean = this and (1L shl i) > 0 infix fun Long.xorBit(i: Int): Long = this xor (1L shl i) fun largerStackSize(stackSizeMegaBytes: Int = 100, action: () -> Unit) { Thread(null, action, "", 1024L * 1024 * stackSizeMegaBytes).apply { start() join() } } // ################################################################################################# /** The lower bound of [low, high], which `predicate.test(it)` is true. */ fun lowerBound(low: Int, high: Int, predicate: IntPredicate): Int? { if (low > high) return null var l = low var h = high while (l < h) { val m = (l + h) / 2 if (predicate.test(m)) { h = m } else { l = m + 1 } } return l.takeIf(predicate::test) } /** The upper bound of [low, high], which `predicate.test(it)` is true. */ fun upperBound(low: Int, high: Int, predicate: IntPredicate): Int? { if (low > high) return null var l = low var h = high while (l < h) { val m = (l + h + 1) / 2 if (predicate.test(m)) { l = m } else { h = m - 1 } } return l.takeIf(predicate::test) } fun solve() { val n = readInt() val a = readInts(n) val lAns = IntArray(n) val l = mutableListOf<Int>() for (i in a.indices) { if (l.isEmpty() || a[i] > l.last()) { l += a[i] lAns[i] = l.size } else { val x = lowerBound(0, l.size - 1) { l[it] >= a[i] }!! lAns[i] = x + 1 l[x] = a[i] } } val rAns = IntArray(n) val r = mutableListOf<Int>() for (i in a.indices.reversed()) { if (r.isEmpty() || a[i] < r.last()) { r += a[i] rAns[i] = r.size } else { val x = lowerBound(0, r.size - 1) { r[it] <= a[i] }!! rAns[i] = x + 1 r[x] = a[i] } } val ans = mutableListOf<Int>() for (i in a.indices) { if (lAns[i] + rAns[i] == l.size + 1) ans += i + 1 } println(ans.size) println(ans.joinToString(" ")) } fun main() { repeat(readInt()) { solve() } // solve() }
Submission Info
Submission Time | |
---|---|
Task | F - Useless for LIS |
User | wangchaohui |
Language | Kotlin (Kotlin/JVM 1.8.20) |
Score | 525 |
Code Size | 3983 Byte |
Status | AC |
Exec Time | 986 ms |
Memory | 78204 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 525 / 525 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_00.txt, 00_sample_01.txt |
All | 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 02_hand_00.txt, 02_hand_01.txt, 02_hand_02.txt, 02_hand_03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_00.txt | AC | 71 ms | 40636 KiB |
00_sample_01.txt | AC | 71 ms | 40760 KiB |
01_random_00.txt | AC | 986 ms | 68544 KiB |
01_random_01.txt | AC | 867 ms | 77032 KiB |
01_random_02.txt | AC | 827 ms | 78204 KiB |
01_random_03.txt | AC | 517 ms | 74248 KiB |
01_random_04.txt | AC | 467 ms | 68656 KiB |
01_random_05.txt | AC | 419 ms | 70112 KiB |
01_random_06.txt | AC | 408 ms | 68936 KiB |
01_random_07.txt | AC | 420 ms | 68676 KiB |
01_random_08.txt | AC | 408 ms | 68792 KiB |
01_random_09.txt | AC | 423 ms | 69828 KiB |
01_random_10.txt | AC | 964 ms | 66496 KiB |
01_random_11.txt | AC | 723 ms | 74556 KiB |
01_random_12.txt | AC | 817 ms | 75920 KiB |
01_random_13.txt | AC | 506 ms | 74828 KiB |
01_random_14.txt | AC | 436 ms | 68708 KiB |
01_random_15.txt | AC | 409 ms | 69284 KiB |
01_random_16.txt | AC | 391 ms | 69220 KiB |
01_random_17.txt | AC | 426 ms | 70420 KiB |
01_random_18.txt | AC | 413 ms | 70020 KiB |
01_random_19.txt | AC | 383 ms | 70128 KiB |
01_random_20.txt | AC | 942 ms | 67920 KiB |
01_random_21.txt | AC | 819 ms | 77644 KiB |
01_random_22.txt | AC | 666 ms | 76832 KiB |
01_random_23.txt | AC | 553 ms | 72288 KiB |
01_random_24.txt | AC | 463 ms | 70596 KiB |
01_random_25.txt | AC | 403 ms | 68044 KiB |
01_random_26.txt | AC | 419 ms | 68024 KiB |
01_random_27.txt | AC | 420 ms | 68096 KiB |
01_random_28.txt | AC | 450 ms | 67996 KiB |
01_random_29.txt | AC | 420 ms | 68228 KiB |
01_random_30.txt | AC | 460 ms | 72552 KiB |
01_random_31.txt | AC | 465 ms | 73204 KiB |
01_random_32.txt | AC | 466 ms | 76360 KiB |
01_random_33.txt | AC | 471 ms | 76544 KiB |
01_random_34.txt | AC | 464 ms | 75736 KiB |
01_random_35.txt | AC | 469 ms | 76148 KiB |
01_random_36.txt | AC | 445 ms | 77176 KiB |
01_random_37.txt | AC | 457 ms | 72412 KiB |
01_random_38.txt | AC | 491 ms | 74456 KiB |
01_random_39.txt | AC | 464 ms | 76736 KiB |
02_hand_00.txt | AC | 62 ms | 40056 KiB |
02_hand_01.txt | AC | 382 ms | 69876 KiB |
02_hand_02.txt | AC | 407 ms | 77308 KiB |
02_hand_03.txt | AC | 427 ms | 77836 KiB |