結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー tentententen
提出日時 2023-06-30 11:55:54
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 4,832 bytes
コンパイル時間 4,433 ms
コンパイル使用メモリ 88,380 KB
実行使用メモリ 98,020 KB
最終ジャッジ日時 2023-09-21 05:50:51
合計ジャッジ時間 48,229 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
50,556 KB
testcase_01 AC 61 ms
51,180 KB
testcase_02 AC 96 ms
55,668 KB
testcase_03 AC 840 ms
78,024 KB
testcase_04 AC 1,066 ms
83,660 KB
testcase_05 WA -
testcase_06 AC 1,112 ms
78,232 KB
testcase_07 WA -
testcase_08 AC 1,002 ms
83,092 KB
testcase_09 AC 1,177 ms
81,564 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 1,257 ms
87,388 KB
testcase_19 WA -
testcase_20 AC 504 ms
67,052 KB
testcase_21 AC 581 ms
63,296 KB
testcase_22 WA -
testcase_23 AC 607 ms
65,148 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 818 ms
70,988 KB
testcase_29 AC 1,474 ms
97,600 KB
testcase_30 AC 1,283 ms
98,020 KB
testcase_31 AC 959 ms
73,912 KB
testcase_32 AC 1,641 ms
96,140 KB
testcase_33 AC 1,496 ms
96,780 KB
testcase_34 AC 1,509 ms
95,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
    
}
0