結果
| 問題 |
No.1675 Strange Minimum Query
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-10-19 11:05:38 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,465 ms / 2,000 ms |
| コード長 | 2,850 bytes |
| コンパイル時間 | 3,172 ms |
| コンパイル使用メモリ | 80,248 KB |
| 実行使用メモリ | 107,680 KB |
| 最終ジャッジ日時 | 2024-09-20 06:15:50 |
| 合計ジャッジ時間 | 38,222 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
static final int MAX = 1000000000;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int q = sc.nextInt();
int[] ans = new int[n];
TreeSet<Integer> remain = new TreeSet<>();
for (int i = 0; i < n; i++) {
remain.add(i);
}
HashMap<Integer, TreeSet<Integer>> used = new HashMap<>();
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);
for (Query x : queries) {
Integer key = x.left;
while ((key = remain.ceiling(key)) != null) {
if (key > x.right) {
break;
}
if (!used.containsKey(x.value)) {
used.put(x.value, new TreeSet<>());
}
used.get(x.value).add(key);
ans[key] = x.value;
remain.remove(key);
}
if (!used.containsKey(x.value)) {
System.out.println(-1);
return;
}
Integer next = used.get(x.value).ceiling(x.left);
if (next == null || next > x.right) {
System.out.println(-1);
return;
}
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
if (i > 0) {
sb.append(" ");
}
if (ans[i] == 0) {
ans[i] = MAX;
}
sb.append(ans[i]);
}
System.out.println(sb);
}
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 Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public String nextLine() throws Exception {
return br.readLine();
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten