結果

問題 No.1675 Strange Minimum Query
ユーザー ks2mks2m
提出日時 2021-09-10 21:38:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,230 ms / 2,000 ms
コード長 1,387 bytes
コンパイル時間 3,275 ms
コンパイル使用メモリ 79,260 KB
実行使用メモリ 88,836 KB
最終ジャッジ日時 2023-09-02 16:19:56
合計ジャッジ時間 33,312 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
50,608 KB
testcase_01 AC 53 ms
50,336 KB
testcase_02 AC 53 ms
50,468 KB
testcase_03 AC 503 ms
63,104 KB
testcase_04 AC 545 ms
65,100 KB
testcase_05 AC 295 ms
60,328 KB
testcase_06 AC 530 ms
65,860 KB
testcase_07 AC 567 ms
65,864 KB
testcase_08 AC 58 ms
51,048 KB
testcase_09 AC 122 ms
53,992 KB
testcase_10 AC 970 ms
73,752 KB
testcase_11 AC 375 ms
64,872 KB
testcase_12 AC 1,024 ms
77,656 KB
testcase_13 AC 856 ms
77,352 KB
testcase_14 AC 1,081 ms
88,836 KB
testcase_15 AC 1,081 ms
88,156 KB
testcase_16 AC 54 ms
50,352 KB
testcase_17 AC 370 ms
60,128 KB
testcase_18 AC 445 ms
63,248 KB
testcase_19 AC 589 ms
67,216 KB
testcase_20 AC 831 ms
70,076 KB
testcase_21 AC 782 ms
72,444 KB
testcase_22 AC 915 ms
73,708 KB
testcase_23 AC 782 ms
63,824 KB
testcase_24 AC 786 ms
70,124 KB
testcase_25 AC 612 ms
62,564 KB
testcase_26 AC 460 ms
61,160 KB
testcase_27 AC 800 ms
74,056 KB
testcase_28 AC 556 ms
67,408 KB
testcase_29 AC 502 ms
68,588 KB
testcase_30 AC 475 ms
63,908 KB
testcase_31 AC 837 ms
66,524 KB
testcase_32 AC 999 ms
77,808 KB
testcase_33 AC 972 ms
76,972 KB
testcase_34 AC 1,063 ms
79,640 KB
testcase_35 AC 1,230 ms
81,252 KB
testcase_36 AC 1,186 ms
81,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);
		PriorityQueue<Obj> que = new PriorityQueue<>((o1, o2) -> o2.b - o1.b);
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			Obj o = new Obj();
			o.l = Integer.parseInt(sa[0]) - 1;
			o.r = Integer.parseInt(sa[1]);
			o.b = Integer.parseInt(sa[2]);
			que.add(o);
		}
		br.close();

		int[] a = new int[n];
		Arrays.fill(a, 1);
		TreeSet<Integer> set = new TreeSet<>();
		for (int i = 0; i < n; i++) {
			set.add(i);
		}
		Obj pre = null;
		while (!que.isEmpty()) {
			Obj o = que.poll();
			Set<Integer> ss = set.subSet(o.l, o.r);
			if (pre != null && o.b < pre.b && ss.isEmpty()) {
				System.out.println(-1);
				return;
			}
			for (int i : ss) {
				a[i] = o.b;
			}
			ss.clear();
			pre = o;
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			sb.append(a[i]).append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb.toString());
	}

	static class Obj {
		int l, r, b;
	}
}
0