結果
問題 | No.2421 entersys? |
ユーザー | tenten |
提出日時 | 2023-08-17 11:13:22 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 2,494 ms / 3,000 ms |
コード長 | 4,904 bytes |
コンパイル時間 | 3,041 ms |
コンパイル使用メモリ | 86,396 KB |
実行使用メモリ | 135,300 KB |
最終ジャッジ日時 | 2024-11-26 07:26:41 |
合計ジャッジ時間 | 41,813 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
36,872 KB |
testcase_01 | AC | 89 ms
38,568 KB |
testcase_02 | AC | 133 ms
40,368 KB |
testcase_03 | AC | 60 ms
37,536 KB |
testcase_04 | AC | 88 ms
38,408 KB |
testcase_05 | AC | 109 ms
39,264 KB |
testcase_06 | AC | 114 ms
39,192 KB |
testcase_07 | AC | 108 ms
39,032 KB |
testcase_08 | AC | 130 ms
40,404 KB |
testcase_09 | AC | 140 ms
40,676 KB |
testcase_10 | AC | 89 ms
38,268 KB |
testcase_11 | AC | 1,867 ms
114,488 KB |
testcase_12 | AC | 2,029 ms
113,400 KB |
testcase_13 | AC | 1,839 ms
114,320 KB |
testcase_14 | AC | 1,857 ms
114,256 KB |
testcase_15 | AC | 1,868 ms
113,628 KB |
testcase_16 | AC | 1,974 ms
124,904 KB |
testcase_17 | AC | 1,929 ms
124,772 KB |
testcase_18 | AC | 1,959 ms
124,872 KB |
testcase_19 | AC | 2,066 ms
124,832 KB |
testcase_20 | AC | 1,951 ms
124,740 KB |
testcase_21 | AC | 1,501 ms
109,588 KB |
testcase_22 | AC | 1,445 ms
100,668 KB |
testcase_23 | AC | 2,350 ms
135,300 KB |
testcase_24 | AC | 2,304 ms
135,288 KB |
testcase_25 | AC | 2,494 ms
134,920 KB |
testcase_26 | AC | 1,537 ms
107,760 KB |
testcase_27 | AC | 1,525 ms
108,040 KB |
testcase_28 | AC | 1,541 ms
107,872 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(); 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(); } }