結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー tentententen
提出日時 2022-06-23 09:19:36
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 3,445 bytes
コンパイル時間 2,318 ms
コンパイル使用メモリ 78,732 KB
実行使用メモリ 78,964 KB
最終ジャッジ日時 2024-04-24 14:50:52
合計ジャッジ時間 10,914 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
42,200 KB
testcase_01 AC 52 ms
36,696 KB
testcase_02 AC 131 ms
59,764 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        SegmentTree st = new SegmentTree(n);
        for (int i = 0; i < k; i++) {
            st.update(new Wall(i, sc.nextInt() - 1, sc.nextInt() - 1, sc.nextInt(), sc.nextInt()));
        }
        StringBuilder sb = new StringBuilder();
        PriorityQueue<Wall> queue = new PriorityQueue<>();
        while (q-- > 0) {
            int idx = sc.nextInt() - 1;
            long height = sc.nextLong();
            st.query(idx, queue);
            while(queue.size() > 0) {
                Wall w = queue.poll();
                height -= w.height;
                if (height <= 0) {
                    sb.append(w.color).append("\n");
                    break;
                }
            }
            if (height > 0) {
                sb.append("-1\n");
            }
            queue.clear();
        }
        System.out.print(sb);
    }
}
class Wall implements Comparable<Wall> {
    int idx;
    int left;
    int right;
    int height;
    int color;
    
    public Wall(int idx, int left, int right, int color, int height) {
        this.idx = idx;
        this.left = left;
        this.right = right;
        this.height = height;
        this.color = color;
    }
    
    public int compareTo(Wall another) {
        return idx - another.idx;
    }
}
class SegmentTree {
    static final int INF = Integer.MAX_VALUE;
    int size;
    int base;
    ArrayList<ArrayList<Wall>> tree = new ArrayList<>();

    public SegmentTree(int size) {
        this.size = size;
        base = 1;
        while (base < size) {
            base <<= 1;
        }
        for (int i = 0; i < base * 2 - 1; i++) {
            tree.add(new ArrayList<>());
        }
    }
    
    public void query(int idx, PriorityQueue<Wall> queue) {
        queryTree(idx + base - 1, queue);
    }
    
    public void queryTree(int idx, PriorityQueue<Wall> queue) {
        queue.addAll(tree.get(idx));
        if (idx == 0) {
            return;
        }
        queryTree((idx - 1) / 2, queue);
    }
    
    public void update(Wall wall) {
        updateTree(0, 0, base, wall);
    }
    
    public void updateTree(int idx, int left, int right, Wall wall) {
        if (wall.left >= right || wall.right < left) {
            return;
        }
        if (wall.left <= left && right - 1 <= wall.right) {
            tree.get(idx).add(wall);
            return;
        }
        updateTree(2 * idx + 1, left, (left + right) / 2, wall);
        updateTree(2 * idx + 2, (left + right) / 2, right, wall);
    }
    
 }
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0