結果
| 問題 |
No.2930 Larger Mex
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2024-10-21 12:51:45 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 445 ms / 2,000 ms |
| コード長 | 2,384 bytes |
| コンパイル時間 | 2,960 ms |
| コンパイル使用メモリ | 82,236 KB |
| 実行使用メモリ | 68,568 KB |
| 最終ジャッジ日時 | 2024-10-21 12:52:14 |
| 合計ジャッジ時間 | 25,932 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 50 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int m = sc.nextInt();
if (m == 0) {
System.out.println(IntStream.range(0, n).mapToObj(i -> String.valueOf(n - i)).collect(Collectors.joining("\n")));
return;
}
int[] values = new int[n];
for (int i = 0; i < n; i++) {
values[i] = sc.nextInt();
}
int[] imos = new int[n + 2];
int[] counts = new int[m];
int current = 0;
int right = 0;
for (int i = 0; i < n; i++) {
while (right < n && current < m) {
if (values[right] < m) {
counts[values[right]]++;
if (counts[values[right]] == 1) {
current++;
}
}
right++;
}
if (current == m) {
imos[right - i]++;
imos[n - i + 1]--;
}
if (values[i] < m) {
counts[values[i]]--;
if (counts[values[i]] == 0) {
current--;
}
}
}
String result = IntStream.rangeClosed(1, n).mapToObj(i -> {
imos[i] += imos[i - 1];
return String.valueOf(imos[i]);
}).collect(Collectors.joining("\n"));
System.out.println(result);
}
}
class Scanner {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
public Scanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
} catch (Exception e) {
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String next() {
try {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
return st.nextToken();
}
}
}
tenten