結果
問題 | No.878 Range High-Element Query |
ユーザー | tenten |
提出日時 | 2022-08-29 14:05:14 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 872 ms / 2,000 ms |
コード長 | 2,411 bytes |
コンパイル時間 | 2,503 ms |
コンパイル使用メモリ | 79,472 KB |
実行使用メモリ | 67,716 KB |
最終ジャッジ日時 | 2024-04-24 04:58:32 |
合計ジャッジ時間 | 11,340 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
37,308 KB |
testcase_01 | AC | 87 ms
38,072 KB |
testcase_02 | AC | 96 ms
38,864 KB |
testcase_03 | AC | 93 ms
38,340 KB |
testcase_04 | AC | 95 ms
38,092 KB |
testcase_05 | AC | 101 ms
38,324 KB |
testcase_06 | AC | 74 ms
37,240 KB |
testcase_07 | AC | 62 ms
37,056 KB |
testcase_08 | AC | 99 ms
38,328 KB |
testcase_09 | AC | 107 ms
38,636 KB |
testcase_10 | AC | 88 ms
37,984 KB |
testcase_11 | AC | 832 ms
64,064 KB |
testcase_12 | AC | 789 ms
64,120 KB |
testcase_13 | AC | 702 ms
58,800 KB |
testcase_14 | AC | 599 ms
55,868 KB |
testcase_15 | AC | 794 ms
63,368 KB |
testcase_16 | AC | 847 ms
67,232 KB |
testcase_17 | AC | 872 ms
67,716 KB |
testcase_18 | AC | 865 ms
66,968 KB |
ソースコード
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 q = sc.nextInt(); PriorityQueue<Unit> queue = new PriorityQueue<>(); for (int i = 0; i < n; i++) { queue.add(new Unit(sc.nextInt(), i)); } TreeSet<Integer> idxes = new TreeSet<>(); idxes.add(n); int[][] nexts = new int[17][n + 1]; while (queue.size() > 0) { Unit u = queue.poll(); nexts[0][u.idx] = idxes.higher(u.idx); idxes.add(u.idx); } nexts[0][n] = n; for (int i = 1; i < 17; i++) { for (int j = 0; j <= n; j++) { nexts[i][j] = nexts[i - 1][nexts[i - 1][j]]; } } StringBuilder sb = new StringBuilder(); while (q-- > 0) { sc.nextInt(); int left = sc.nextInt() - 1; int right = sc.nextInt() - 1; int ans = 1; for (int i = 16; i >= 0; i--) { if (nexts[i][left] <= right) { left = nexts[i][left]; ans += (1 << i); } } sb.append(ans).append("\n"); } System.out.print(sb); } static class Unit implements Comparable<Unit> { int value; int idx; public Unit(int value, int idx) { this.value = value; this.idx = idx; } public int compareTo(Unit another) { return another.value - value; } } } 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 String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }