結果
問題 | No.1675 Strange Minimum Query |
ユーザー | tenten |
提出日時 | 2023-01-13 17:02:07 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,134 ms / 2,000 ms |
コード長 | 3,266 bytes |
コンパイル時間 | 2,572 ms |
コンパイル使用メモリ | 92,840 KB |
実行使用メモリ | 92,460 KB |
最終ジャッジ日時 | 2024-06-06 18:42:51 |
合計ジャッジ時間 | 34,008 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 59 ms
50,560 KB |
testcase_01 | AC | 48 ms
50,148 KB |
testcase_02 | AC | 57 ms
50,444 KB |
testcase_03 | AC | 624 ms
63,892 KB |
testcase_04 | AC | 676 ms
68,640 KB |
testcase_05 | AC | 418 ms
66,832 KB |
testcase_06 | AC | 703 ms
63,592 KB |
testcase_07 | AC | 775 ms
67,660 KB |
testcase_08 | AC | 64 ms
51,060 KB |
testcase_09 | AC | 115 ms
52,828 KB |
testcase_10 | AC | 894 ms
78,952 KB |
testcase_11 | AC | 513 ms
69,340 KB |
testcase_12 | AC | 950 ms
82,120 KB |
testcase_13 | AC | 942 ms
92,460 KB |
testcase_14 | AC | 823 ms
85,728 KB |
testcase_15 | AC | 858 ms
89,676 KB |
testcase_16 | AC | 60 ms
50,772 KB |
testcase_17 | AC | 454 ms
63,532 KB |
testcase_18 | AC | 467 ms
65,632 KB |
testcase_19 | AC | 745 ms
85,064 KB |
testcase_20 | AC | 855 ms
79,208 KB |
testcase_21 | AC | 855 ms
86,724 KB |
testcase_22 | AC | 915 ms
80,668 KB |
testcase_23 | AC | 707 ms
68,232 KB |
testcase_24 | AC | 702 ms
76,328 KB |
testcase_25 | AC | 544 ms
65,312 KB |
testcase_26 | AC | 529 ms
66,428 KB |
testcase_27 | AC | 890 ms
89,756 KB |
testcase_28 | AC | 632 ms
74,516 KB |
testcase_29 | AC | 662 ms
80,388 KB |
testcase_30 | AC | 540 ms
68,112 KB |
testcase_31 | AC | 733 ms
70,676 KB |
testcase_32 | AC | 1,001 ms
88,464 KB |
testcase_33 | AC | 977 ms
90,960 KB |
testcase_34 | AC | 979 ms
82,348 KB |
testcase_35 | AC | 1,106 ms
81,336 KB |
testcase_36 | AC | 1,134 ms
81,732 KB |
ソースコード
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(); } }