結果
問題 | No.1115 二つの数列 / Two Sequences |
ユーザー | 箱星 |
提出日時 | 2020-09-20 04:33:22 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 861 ms / 2,000 ms |
コード長 | 1,998 bytes |
コンパイル時間 | 16,858 ms |
コンパイル使用メモリ | 452,732 KB |
実行使用メモリ | 90,984 KB |
最終ジャッジ日時 | 2024-06-24 04:40:02 |
合計ジャッジ時間 | 37,587 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 489 ms
64,128 KB |
testcase_01 | AC | 321 ms
58,252 KB |
testcase_02 | AC | 313 ms
58,180 KB |
testcase_03 | AC | 750 ms
88,120 KB |
testcase_04 | AC | 822 ms
89,620 KB |
testcase_05 | AC | 771 ms
83,708 KB |
testcase_06 | AC | 735 ms
78,740 KB |
testcase_07 | AC | 825 ms
90,984 KB |
testcase_08 | AC | 430 ms
57,404 KB |
testcase_09 | AC | 600 ms
72,680 KB |
testcase_10 | AC | 665 ms
90,400 KB |
testcase_11 | AC | 321 ms
53,972 KB |
testcase_12 | AC | 829 ms
89,040 KB |
testcase_13 | AC | 853 ms
89,472 KB |
testcase_14 | AC | 861 ms
90,104 KB |
testcase_15 | AC | 316 ms
54,108 KB |
testcase_16 | AC | 318 ms
53,984 KB |
testcase_17 | AC | 319 ms
54,084 KB |
testcase_18 | AC | 320 ms
54,116 KB |
testcase_19 | AC | 321 ms
54,292 KB |
testcase_20 | AC | 320 ms
54,040 KB |
testcase_21 | AC | 325 ms
54,032 KB |
testcase_22 | AC | 314 ms
54,312 KB |
testcase_23 | AC | 490 ms
58,452 KB |
testcase_24 | AC | 592 ms
66,404 KB |
testcase_25 | AC | 730 ms
77,508 KB |
testcase_26 | AC | 531 ms
61,340 KB |
testcase_27 | AC | 630 ms
68,680 KB |
testcase_28 | AC | 684 ms
74,396 KB |
testcase_29 | AC | 757 ms
79,372 KB |
testcase_30 | AC | 839 ms
90,944 KB |
testcase_31 | AC | 575 ms
63,992 KB |
testcase_32 | AC | 530 ms
60,636 KB |
testcase_33 | AC | 645 ms
84,864 KB |
testcase_34 | AC | 326 ms
54,212 KB |
testcase_35 | AC | 321 ms
54,204 KB |
testcase_36 | AC | 317 ms
54,144 KB |
testcase_37 | AC | 323 ms
54,176 KB |
testcase_38 | AC | 322 ms
54,220 KB |
testcase_39 | AC | 320 ms
53,944 KB |
ソースコード
import java.io.BufferedReader import java.io.InputStream import java.io.InputStreamReader import java.io.PrintWriter import java.util.* fun compress(a: Array<Int>): Array<Int> { val n = a.count() val b = a.sorted().distinct().toTypedArray() val c = Array(n) { 0 } for (i in 0 until n) { c[i] = Arrays.binarySearch(b, a[i]) } return c } class BIT(private val n: Int) { private val data = LongArray(n) { 0 } fun add(i: Int, x: Long) { var p = i + 1 while (p <= n) { data[p - 1] += x p += p and -p } } fun sum(l: Int, r: Int): Long { return sum(r) - sum(l) } private fun sum(i: Int): Long { var r = i var s = 0L while(r > 0) { s += data[r - 1] r -= r and -r } return s } } fun inversionNumber(a: Array<Int>): Long { val b = compress(a) val n = a.count() val bit = BIT(n) var ans = 0L for (i in 0 until n) { ans += i - bit.sum(0, b[i]) bit.add(b[i], 1) } return ans } fun PrintWriter.solve(sc: FastScanner) { val n = sc.nextInt() val a = Array(n) { sc.nextInt() } val b = Array(n) { sc.nextInt() } val new = Array(n + 1) { 0 } for (i in 0 until n) { new[b[i]] = i + 1 } for (i in 0 until n) { a[i] = new[a[i]] } println(inversionNumber(a)) } fun main() { val writer = PrintWriter(System.out, false) writer.solve(FastScanner(System.`in`)) writer.flush() } class FastScanner(s: InputStream) { private var st = StringTokenizer("") private val br = BufferedReader(InputStreamReader(s)) 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() fun ready() = br.ready() }