結果
| 問題 | No.694 square1001 and Permutation 3 |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-01-25 21:44:03 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,709 bytes |
| 記録 | |
| コンパイル時間 | 3,576 ms |
| コンパイル使用メモリ | 84,068 KB |
| 実行使用メモリ | 123,780 KB |
| 最終ジャッジ日時 | 2026-03-06 23:32:03 |
| 合計ジャッジ時間 | 26,986 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 TLE * 5 |
ソースコード
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);
}
}
tenten