結果
問題 | No.1675 Strange Minimum Query |
ユーザー | tenten |
提出日時 | 2021-10-19 11:05:38 |
言語 | Java21 (openjdk 21) |
結果 |
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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
36,972 KB |
testcase_01 | AC | 47 ms
37,056 KB |
testcase_02 | AC | 44 ms
37,092 KB |
testcase_03 | AC | 638 ms
53,448 KB |
testcase_04 | AC | 725 ms
58,796 KB |
testcase_05 | AC | 638 ms
58,540 KB |
testcase_06 | AC | 708 ms
54,828 KB |
testcase_07 | AC | 891 ms
60,412 KB |
testcase_08 | AC | 50 ms
37,280 KB |
testcase_09 | AC | 118 ms
39,804 KB |
testcase_10 | AC | 1,179 ms
81,940 KB |
testcase_11 | AC | 589 ms
62,768 KB |
testcase_12 | AC | 1,362 ms
88,632 KB |
testcase_13 | AC | 989 ms
81,256 KB |
testcase_14 | AC | 1,349 ms
107,680 KB |
testcase_15 | AC | 1,408 ms
106,504 KB |
testcase_16 | AC | 49 ms
36,644 KB |
testcase_17 | AC | 457 ms
51,152 KB |
testcase_18 | AC | 513 ms
54,344 KB |
testcase_19 | AC | 813 ms
73,480 KB |
testcase_20 | AC | 1,023 ms
72,180 KB |
testcase_21 | AC | 911 ms
76,900 KB |
testcase_22 | AC | 981 ms
79,724 KB |
testcase_23 | AC | 747 ms
59,956 KB |
testcase_24 | AC | 930 ms
68,328 KB |
testcase_25 | AC | 677 ms
56,416 KB |
testcase_26 | AC | 553 ms
56,896 KB |
testcase_27 | AC | 856 ms
77,820 KB |
testcase_28 | AC | 1,465 ms
86,448 KB |
testcase_29 | AC | 668 ms
71,332 KB |
testcase_30 | AC | 551 ms
57,248 KB |
testcase_31 | AC | 794 ms
65,248 KB |
testcase_32 | AC | 1,156 ms
82,104 KB |
testcase_33 | AC | 1,136 ms
82,268 KB |
testcase_34 | AC | 1,253 ms
83,160 KB |
testcase_35 | AC | 1,279 ms
89,892 KB |
testcase_36 | AC | 1,260 ms
90,704 KB |
ソースコード
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(); } }