結果

問題 No.1675 Strange Minimum Query
ユーザー tentententen
提出日時 2021-10-19 11:05:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,527 ms / 2,000 ms
コード長 2,850 bytes
コンパイル時間 4,515 ms
コンパイル使用メモリ 80,140 KB
実行使用メモリ 122,468 KB
最終ジャッジ日時 2023-10-20 10:41:58
合計ジャッジ時間 44,173 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
53,636 KB
testcase_01 AC 54 ms
53,632 KB
testcase_02 AC 53 ms
53,632 KB
testcase_03 AC 699 ms
68,872 KB
testcase_04 AC 819 ms
73,740 KB
testcase_05 AC 728 ms
71,376 KB
testcase_06 AC 740 ms
68,928 KB
testcase_07 AC 950 ms
74,904 KB
testcase_08 AC 56 ms
53,640 KB
testcase_09 AC 125 ms
56,504 KB
testcase_10 AC 1,332 ms
98,564 KB
testcase_11 AC 638 ms
77,672 KB
testcase_12 AC 1,235 ms
104,904 KB
testcase_13 AC 1,034 ms
96,604 KB
testcase_14 AC 1,401 ms
122,468 KB
testcase_15 AC 1,498 ms
122,092 KB
testcase_16 AC 54 ms
53,616 KB
testcase_17 AC 449 ms
66,568 KB
testcase_18 AC 544 ms
68,892 KB
testcase_19 AC 755 ms
88,324 KB
testcase_20 AC 1,117 ms
87,884 KB
testcase_21 AC 976 ms
90,180 KB
testcase_22 AC 1,062 ms
96,088 KB
testcase_23 AC 823 ms
72,772 KB
testcase_24 AC 959 ms
81,452 KB
testcase_25 AC 612 ms
69,408 KB
testcase_26 AC 573 ms
69,800 KB
testcase_27 AC 921 ms
90,128 KB
testcase_28 AC 1,527 ms
98,220 KB
testcase_29 AC 711 ms
83,932 KB
testcase_30 AC 565 ms
70,716 KB
testcase_31 AC 887 ms
79,976 KB
testcase_32 AC 1,340 ms
96,912 KB
testcase_33 AC 1,210 ms
96,928 KB
testcase_34 AC 1,213 ms
95,900 KB
testcase_35 AC 1,380 ms
105,476 KB
testcase_36 AC 1,397 ms
105,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
}
0