結果
| 問題 |
No.1675 Strange Minimum Query
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2023-01-13 17:02:07 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,530 ms / 2,000 ms |
| コード長 | 3,266 bytes |
| コンパイル時間 | 2,922 ms |
| コンパイル使用メモリ | 92,240 KB |
| 実行使用メモリ | 83,668 KB |
| 最終ジャッジ日時 | 2024-12-24 11:50:08 |
| 合計ジャッジ時間 | 36,945 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.stream.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int q = sc.nextInt();
Query[] queries = new Query[q];
for (int i = 0; i < q; i++) {
queries[i] = new Query(sc.nextInt() - 1, sc.nextInt() - 1, sc.nextInt());
}
Arrays.sort(queries);
TreeSet<Integer> all = new TreeSet<>();
for (int i = 0; i < n; i++) {
all.add(i);
}
int[] ans = new int[n];
Arrays.fill(ans, 1000000000);
TreeSet<Integer> store = new TreeSet<>();
int prev = Integer.MAX_VALUE;
for (Query x : queries) {
if (prev != x.value) {
store.clear();
}
Integer key = store.floor(x.right);
boolean enable = (key != null && key >= x.left);
ArrayList<Integer> list = new ArrayList<>();
key = x.left - 1;
while ((key = all.higher(key)) != null) {
if (key > x.right) {
break;
}
all.remove(key);
list.add(key);
}
if (!enable && list.size() == 0) {
System.out.println(-1);
return;
}
for (int y : list) {
ans[y] = x.value;
store.add(y);
}
prev = x.value;
}
System.out.println(String.join(" ", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new)));
}
static class Query implements Comparable<Query> {
int left;
int right;
int value;
public Query(int left, int right, int value) {
this.left = left;
this.right = right;
this.value = value;
}
public int compareTo(Query another) {
return another.value - value;
}
}
}
class Utilities {
static String arrayToLineString(Object[] arr) {
return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
}
static String arrayToLineString(int[] arr) {
return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public int[] nextIntArray() throws Exception {
return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
}
public String next() throws Exception {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten