結果
問題 | No.1982 [Cherry 4th Tune B] 絶険 |
ユーザー | tenten |
提出日時 | 2023-06-30 11:55:54 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,832 bytes |
コンパイル時間 | 2,976 ms |
コンパイル使用メモリ | 96,068 KB |
実行使用メモリ | 99,580 KB |
最終ジャッジ日時 | 2024-07-07 00:18:21 |
合計ジャッジ時間 | 34,346 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
51,012 KB |
testcase_01 | AC | 53 ms
50,936 KB |
testcase_02 | AC | 74 ms
52,104 KB |
testcase_03 | AC | 645 ms
76,608 KB |
testcase_04 | AC | 740 ms
75,200 KB |
testcase_05 | WA | - |
testcase_06 | AC | 783 ms
76,336 KB |
testcase_07 | WA | - |
testcase_08 | AC | 753 ms
80,412 KB |
testcase_09 | AC | 850 ms
79,960 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 916 ms
85,940 KB |
testcase_19 | WA | - |
testcase_20 | AC | 402 ms
66,884 KB |
testcase_21 | AC | 456 ms
63,172 KB |
testcase_22 | WA | - |
testcase_23 | AC | 482 ms
65,644 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 641 ms
69,816 KB |
testcase_29 | AC | 1,223 ms
99,580 KB |
testcase_30 | AC | 995 ms
96,400 KB |
testcase_31 | AC | 745 ms
71,596 KB |
testcase_32 | AC | 1,103 ms
92,504 KB |
testcase_33 | AC | 1,041 ms
93,416 KB |
testcase_34 | AC | 1,051 ms
93,500 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static final int MOD = 998244353; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int k = sc.nextInt(); int q = sc.nextInt(); PriorityQueue<KeyValue> walls = new PriorityQueue<>(); int[] lefts = new int[k]; int[] rights = new int[k]; int[] colors = new int[k]; int[] heights = new int[k]; for (int i = 0; i < k; i++) { lefts[i] = sc.nextInt(); rights[i] = sc.nextInt(); colors[i] = sc.nextInt(); heights[i] = sc.nextInt(); walls.add(new KeyValue(i, lefts[i])); } PriorityQueue<KeyValue> questions = new PriorityQueue<>(); long[] values = new long[q]; for (int i = 0; i < q; i++) { questions.add(new KeyValue(i, sc.nextInt())); values[i] = sc.nextLong(); } BinaryIndexedTree bit = new BinaryIndexedTree(n + 1); PriorityQueue<KeyValue> inQueue = new PriorityQueue<>(); int[] ans = new int[q]; for (int i = 1; i <= n; i++) { while (walls.size() > 0 && walls.peek().value == i) { KeyValue x = walls.poll(); bit.add(x.idx + 1, heights[x.idx]); inQueue.add(new KeyValue(x.idx, rights[x.idx])); } while (questions.size() > 0 && questions.peek().value == i) { KeyValue x = questions.poll(); if (bit.getSum(n) < values[x.idx]) { ans[x.idx] = -1; } else { int left = 0; int right = n; while (right - left > 1) { int m = (left + right) / 2; if (bit.getSum(m) >= values[x.idx]) { right = m; } else { left = m; } } ans[x.idx] = colors[left]; } } while (inQueue.size() > 0 && inQueue.peek().value == i) { KeyValue x = inQueue.poll(); bit.add(x.idx + 1, -heights[x.idx]); } } System.out.println(String.join("\n", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new))); } static class KeyValue implements Comparable<KeyValue> { int idx; int value; public KeyValue(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(KeyValue another) { return value - another.value; } } } class BinaryIndexedTree { int size; long[] tree; public BinaryIndexedTree(int size) { this.size = size; tree = new long[size]; } public void add(int idx, long value) { int mask = 1; while (idx < size) { if ((idx & mask) != 0) { tree[idx] += value; idx += mask; } mask <<= 1; } } public long getSum(int from, int to) { return getSum(to) - getSum(from - 1); } public long getSum(int x) { int mask = 1; long 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(); } }