結果
| 問題 | No.2220 Range Insert & Point Mex | 
| コンテスト | |
| ユーザー |  tenten | 
| 提出日時 | 2023-02-20 14:55:09 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                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 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 36 | 
ソースコード
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();
    }
    
}
            
            
            
        