結果
問題 | No.1282 Display Elements |
ユーザー | ks2m |
提出日時 | 2020-11-06 22:30:42 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,115 ms / 2,000 ms |
コード長 | 1,572 bytes |
コンパイル時間 | 5,023 ms |
コンパイル使用メモリ | 75,388 KB |
実行使用メモリ | 76,500 KB |
最終ジャッジ日時 | 2023-09-29 19:10:31 |
合計ジャッジ時間 | 12,684 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
49,508 KB |
testcase_01 | AC | 45 ms
49,416 KB |
testcase_02 | AC | 45 ms
49,680 KB |
testcase_03 | AC | 44 ms
49,804 KB |
testcase_04 | AC | 45 ms
49,528 KB |
testcase_05 | AC | 44 ms
49,352 KB |
testcase_06 | AC | 43 ms
49,440 KB |
testcase_07 | AC | 43 ms
49,560 KB |
testcase_08 | AC | 44 ms
49,424 KB |
testcase_09 | AC | 44 ms
49,352 KB |
testcase_10 | AC | 72 ms
50,360 KB |
testcase_11 | AC | 73 ms
50,380 KB |
testcase_12 | AC | 49 ms
49,440 KB |
testcase_13 | AC | 60 ms
50,404 KB |
testcase_14 | AC | 86 ms
53,036 KB |
testcase_15 | AC | 951 ms
75,460 KB |
testcase_16 | AC | 489 ms
66,968 KB |
testcase_17 | AC | 854 ms
70,696 KB |
testcase_18 | AC | 598 ms
69,248 KB |
testcase_19 | AC | 360 ms
66,816 KB |
testcase_20 | AC | 355 ms
65,836 KB |
testcase_21 | AC | 1,073 ms
76,500 KB |
testcase_22 | AC | 433 ms
67,208 KB |
testcase_23 | AC | 1,115 ms
76,492 KB |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.TreeMap; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int n2 = n * 2; String[] sa = br.readLine().split(" "); int[] a = new int[n2]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } sa = br.readLine().split(" "); for (int i = 0; i < n; i++) { a[n + i] = Integer.parseInt(sa[i]); } br.close(); int[] b = zaatu(a); int[] c = Arrays.copyOf(b, n); Arrays.sort(c); BIT bit = new BIT(n2); long ans = 0; for (int i = 0; i < n; i++) { bit.add(b[n + i], 1); ans += bit.sum(c[i] - 1); } System.out.println(ans); } static int[] zaatu(int[] a) { TreeMap<Integer, Integer> map = new TreeMap<>(); for (int i = 0; i < a.length; i++) { map.put(a[i], null); } Integer[] arr = map.keySet().toArray(new Integer[0]); int cnt = 0; for (Integer i : arr) { cnt++; map.put(i, cnt); } int[] b = new int[a.length]; for (int i = 0; i < a.length; i++) { b[i] = map.get(a[i]); } return b; } static class BIT { int n; long[] arr; public BIT(int n) { this.n = n; arr = new long[n + 1]; } void add(int idx, long val) { for (int i = idx; i <= n; i += i & -i) { arr[i] += val; } } long sum(int idx) { long sum = 0; for (int i = idx; i > 0; i -= i & -i) { sum += arr[i]; } return sum; } } }