結果
問題 | No.2220 Range Insert & Point Mex |
ユーザー | tenten |
提出日時 | 2023-02-20 14:55:09 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,383 ms / 2,000 ms |
コード長 | 3,473 bytes |
コンパイル時間 | 5,526 ms |
コンパイル使用メモリ | 92,452 KB |
実行使用メモリ | 84,512 KB |
最終ジャッジ日時 | 2024-07-21 13:03:31 |
合計ジャッジ時間 | 30,426 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 62 ms
37,708 KB |
testcase_01 | AC | 61 ms
38,036 KB |
testcase_02 | AC | 62 ms
37,564 KB |
testcase_03 | AC | 66 ms
37,612 KB |
testcase_04 | AC | 60 ms
37,924 KB |
testcase_05 | AC | 68 ms
37,948 KB |
testcase_06 | AC | 64 ms
38,028 KB |
testcase_07 | AC | 67 ms
37,888 KB |
testcase_08 | AC | 68 ms
37,724 KB |
testcase_09 | AC | 67 ms
37,804 KB |
testcase_10 | AC | 67 ms
37,944 KB |
testcase_11 | AC | 63 ms
37,468 KB |
testcase_12 | AC | 67 ms
37,600 KB |
testcase_13 | AC | 985 ms
71,376 KB |
testcase_14 | AC | 971 ms
71,404 KB |
testcase_15 | AC | 958 ms
71,120 KB |
testcase_16 | AC | 951 ms
71,196 KB |
testcase_17 | AC | 993 ms
71,204 KB |
testcase_18 | AC | 957 ms
71,240 KB |
testcase_19 | AC | 967 ms
70,880 KB |
testcase_20 | AC | 1,383 ms
82,940 KB |
testcase_21 | AC | 1,318 ms
81,556 KB |
testcase_22 | AC | 1,325 ms
83,428 KB |
testcase_23 | AC | 1,056 ms
82,508 KB |
testcase_24 | AC | 1,050 ms
71,872 KB |
testcase_25 | AC | 783 ms
66,080 KB |
testcase_26 | AC | 1,106 ms
84,512 KB |
testcase_27 | AC | 824 ms
70,148 KB |
testcase_28 | AC | 389 ms
52,676 KB |
testcase_29 | AC | 406 ms
52,592 KB |
testcase_30 | AC | 400 ms
51,460 KB |
testcase_31 | AC | 809 ms
66,820 KB |
testcase_32 | AC | 778 ms
68,296 KB |
testcase_33 | AC | 798 ms
67,820 KB |
testcase_34 | AC | 1,228 ms
72,456 KB |
testcase_35 | AC | 1,156 ms
72,672 KB |
testcase_36 | AC | 1,160 ms
78,192 KB |
testcase_37 | AC | 1,199 ms
79,844 KB |
testcase_38 | AC | 1,002 ms
74,152 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(); PriorityQueue<Query> queries = new PriorityQueue<>(); TreeSet<Integer> remain = new TreeSet<>(); for (int i = 0; i <= n; i++) { remain.add(i); } for (int i = 0; i < n; i++) { int left = sc.nextInt(); int right = sc.nextInt(); int value = sc.nextInt(); queries.add(new Query(0, left, value)); queries.add(new Query(2, right, value)); } int q = sc.nextInt(); for (int i = 0; i < q; i++) { queries.add(new Query(1, sc.nextInt(), i)); } int[] ans = new int[q]; HashMap<Integer, Integer> counts = new HashMap<>(); while (queries.size() > 0) { Query x = queries.poll(); if (x.type == 0) { if (!counts.containsKey(x.value)) { counts.put(x.value, 1); remain.remove(x.value); } else { counts.put(x.value, counts.get(x.value) + 1); } } else if (x.type == 1) { ans[x.value] = remain.first(); } else { if (counts.get(x.value) == 1) { counts.remove(x.value); remain.add(x.value); } else { counts.put(x.value, counts.get(x.value) - 1); } } } System.out.println(String.join("\n", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new))); } static class Query implements Comparable<Query> { int type; int idx; int value; public Query(int type, int idx, int value) { this.type = type; this.idx = idx; this.value = value; } public int compareTo(Query another) { if (idx == another.idx) { return type - another.type; } else { return idx - another.idx; } } } } 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(); } }