結果
問題 | No.2220 Range Insert & Point Mex |
ユーザー | tenten |
提出日時 | 2023-02-20 14:55:09 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,647 ms / 2,000 ms |
コード長 | 3,473 bytes |
コンパイル時間 | 3,472 ms |
コンパイル使用メモリ | 92,428 KB |
実行使用メモリ | 95,784 KB |
最終ジャッジ日時 | 2023-09-28 18:23:27 |
合計ジャッジ時間 | 34,163 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 62 ms
50,800 KB |
testcase_01 | AC | 61 ms
51,244 KB |
testcase_02 | AC | 62 ms
51,032 KB |
testcase_03 | AC | 66 ms
51,080 KB |
testcase_04 | AC | 61 ms
51,404 KB |
testcase_05 | AC | 68 ms
51,264 KB |
testcase_06 | AC | 66 ms
50,932 KB |
testcase_07 | AC | 68 ms
51,516 KB |
testcase_08 | AC | 68 ms
50,924 KB |
testcase_09 | AC | 67 ms
51,052 KB |
testcase_10 | AC | 69 ms
51,004 KB |
testcase_11 | AC | 63 ms
50,928 KB |
testcase_12 | AC | 66 ms
51,240 KB |
testcase_13 | AC | 1,056 ms
83,228 KB |
testcase_14 | AC | 1,048 ms
83,188 KB |
testcase_15 | AC | 1,031 ms
82,908 KB |
testcase_16 | AC | 1,059 ms
82,864 KB |
testcase_17 | AC | 1,043 ms
82,716 KB |
testcase_18 | AC | 1,052 ms
82,588 KB |
testcase_19 | AC | 1,097 ms
82,944 KB |
testcase_20 | AC | 1,647 ms
95,784 KB |
testcase_21 | AC | 1,629 ms
94,620 KB |
testcase_22 | AC | 1,619 ms
94,656 KB |
testcase_23 | AC | 1,176 ms
93,668 KB |
testcase_24 | AC | 1,059 ms
82,988 KB |
testcase_25 | AC | 776 ms
77,332 KB |
testcase_26 | AC | 1,131 ms
95,396 KB |
testcase_27 | AC | 851 ms
81,284 KB |
testcase_28 | AC | 408 ms
65,352 KB |
testcase_29 | AC | 422 ms
65,984 KB |
testcase_30 | AC | 420 ms
65,964 KB |
testcase_31 | AC | 819 ms
78,524 KB |
testcase_32 | AC | 785 ms
80,600 KB |
testcase_33 | AC | 792 ms
80,244 KB |
testcase_34 | AC | 1,291 ms
84,616 KB |
testcase_35 | AC | 1,294 ms
84,596 KB |
testcase_36 | AC | 1,298 ms
91,292 KB |
testcase_37 | AC | 1,259 ms
92,412 KB |
testcase_38 | AC | 1,055 ms
86,496 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(); } }