結果

問題 No.2421 entersys?
ユーザー tentententen
提出日時 2023-08-17 11:13:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,400 ms / 3,000 ms
コード長 4,904 bytes
コンパイル時間 2,878 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 135,304 KB
最終ジャッジ日時 2024-05-04 17:59:04
合計ジャッジ時間 40,600 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
36,996 KB
testcase_01 AC 83 ms
38,336 KB
testcase_02 AC 134 ms
40,276 KB
testcase_03 AC 59 ms
37,128 KB
testcase_04 AC 77 ms
38,172 KB
testcase_05 AC 99 ms
39,480 KB
testcase_06 AC 109 ms
39,776 KB
testcase_07 AC 100 ms
39,292 KB
testcase_08 AC 131 ms
40,236 KB
testcase_09 AC 138 ms
40,816 KB
testcase_10 AC 100 ms
38,416 KB
testcase_11 AC 1,824 ms
113,432 KB
testcase_12 AC 1,860 ms
114,480 KB
testcase_13 AC 1,862 ms
114,244 KB
testcase_14 AC 1,899 ms
114,344 KB
testcase_15 AC 1,896 ms
114,448 KB
testcase_16 AC 1,981 ms
124,816 KB
testcase_17 AC 1,949 ms
124,636 KB
testcase_18 AC 1,922 ms
124,648 KB
testcase_19 AC 1,988 ms
124,788 KB
testcase_20 AC 1,955 ms
124,768 KB
testcase_21 AC 1,521 ms
109,668 KB
testcase_22 AC 1,442 ms
99,996 KB
testcase_23 AC 2,186 ms
135,304 KB
testcase_24 AC 2,400 ms
135,192 KB
testcase_25 AC 2,230 ms
135,268 KB
testcase_26 AC 1,476 ms
107,064 KB
testcase_27 AC 1,481 ms
107,896 KB
testcase_28 AC 1,414 ms
107,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        String[] ids = new String[n];
        int[] lefts = new int[n];
        int[] rights = new int[n];
        HashMap<String, TreeMap<Integer, Integer>> logs = new HashMap<>();
        TreeMap<Integer, Integer> compress = new TreeMap<>();
        compress.put(0, null);
        for (int i = 0; i < n; i++) {
            ids[i] = sc.next();
            lefts[i] = sc.nextInt();
            rights[i] = sc.nextInt() + 1;
            if (!logs.containsKey(ids[i])) {
                logs.put(ids[i], new TreeMap<>());
            }
            logs.get(ids[i]).put(lefts[i], rights[i]);
            compress.put(lefts[i], null);
            compress.put(rights[i], null);
        }
        int q = sc.nextInt();
        int[] types = new int[q];
        String[] students = new String[q];
        int[] times = new int[q];
        int[] starts = new int[q];
        int[] ends = new int[q];
        for (int i = 0; i < q; i++) {
            types[i] = sc.nextInt();
            if (types[i] == 1) {
                students[i] = sc.next();
                times[i] = sc.nextInt();
            } else if (types[i] == 2) {
                times[i] = sc.nextInt();
            } else {
                students[i] = sc.next();
                starts[i] = sc.nextInt();
                ends[i] = sc.nextInt() + 1;
                compress.put(starts[i], null);
                compress.put(ends[i], null);
            }
        }
        int idx = 1;
        for (int x : compress.keySet()) {
            compress.put(x, idx++);
        }
        BinaryIndexedTree bit = new BinaryIndexedTree(idx);
        for (int i = 0; i < n; i++) {
            bit.add(compress.get(lefts[i]), 1);
            bit.add(compress.get(rights[i]), -1);
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            if (types[i] == 1) {
                if (!logs.containsKey(students[i]) || logs.get(students[i]).floorEntry(times[i]) == null || logs.get(students[i]).floorEntry(times[i]).getValue() <= times[i]) {
                    sb.append("No\n");
                } else {
                    sb.append("Yes\n");
                }
            } else if (types[i] == 2) {
                sb.append(bit.getSum(compress.floorEntry(times[i]).getValue())).append("\n");
            } else {
                if (!logs.containsKey(students[i])) {
                    logs.put(students[i], new TreeMap<>());
                }
                logs.get(students[i]).put(starts[i], ends[i]);
                bit.add(compress.get(starts[i]), 1);
                bit.add(compress.get(ends[i]), -1);
            }
        }
        System.out.print(sb);
    }
}
class BinaryIndexedTree {
    int size;
    int[] tree;
    
    public BinaryIndexedTree(int size) {
        this.size = size;
        tree = new int[size];
    }
    
    public void add(int idx, int value) {
        int mask = 1;
        while (idx < size) {
            if ((idx & mask) != 0) {
                tree[idx] += value;
                idx += mask;
            }
            mask <<= 1;
        }
    }
    
    public int getSum(int from, int to) {
        return getSum(to) - getSum(from - 1);
    }
    
    public int getSum(int x) {
        int mask = 1;
        int ans = 0;
        while (x > 0) {
            if ((x & mask) != 0) {
                ans += tree[x];
                x -= mask;
            }
            mask <<= 1;
        }
        return ans;
    }
}
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();
    }
    
}
0