結果

問題 No.694 square1001 and Permutation 3
ユーザー tentententen
提出日時 2021-01-25 21:44:03
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,709 bytes
コンパイル時間 5,062 ms
コンパイル使用メモリ 77,152 KB
実行使用メモリ 58,884 KB
最終ジャッジ日時 2023-09-04 20:45:25
合計ジャッジ時間 14,237 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,828 KB
testcase_01 AC 122 ms
55,800 KB
testcase_02 AC 124 ms
56,400 KB
testcase_03 AC 184 ms
56,032 KB
testcase_04 AC 186 ms
58,884 KB
testcase_05 AC 190 ms
56,540 KB
testcase_06 AC 191 ms
55,908 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        long count = 0;
        ArrayList<Integer> list = new ArrayList<>();
        list.add(0);
        list.add(Integer.MAX_VALUE);
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            int left = 0;
            int right = list.size();
            while (right - left > 1) {
                int m = (left + right) / 2;
                if (list.get(m) <= arr[i]) {
                    left = m;
                } else {
                    right = m;
                }
            }
            count += list.size() - right - 1;
            list.add(right, arr[i]);
        }
        StringBuilder sb = new StringBuilder();
        sb.append(count).append("\n");
        for (int i = 0; i < n - 1; i++) {
            int left = 0;
            int right = list.size();
            while (right - left > 1) {
                int m = (left + right) / 2;
                if (list.get(m) < arr[i]) {
                    left = m;
                } else {
                    right = m;
                }
            }
            count -= left;
            left = 0;
            right = list.size();
            while (right - left > 1) {
                int m = (left + right) / 2;
                if (list.get(m) <= arr[i]) {
                    left = m;
                } else {
                    right = m;
                }
            }
            count += list.size() - right - 1;
            sb.append(count).append("\n");
        }
        System.out.print(sb);
    }
    
}
0