結果

問題 No.878 Range High-Element Query
ユーザー H3PO4H3PO4
提出日時 2022-08-20 13:31:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 105,344 KB
最終ジャッジ日時 2024-04-17 12:27:36
合計ジャッジ時間 3,816 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
51,712 KB
testcase_01 AC 51 ms
64,384 KB
testcase_02 AC 51 ms
64,384 KB
testcase_03 AC 49 ms
63,104 KB
testcase_04 AC 51 ms
64,128 KB
testcase_05 AC 65 ms
67,456 KB
testcase_06 AC 44 ms
59,008 KB
testcase_07 AC 42 ms
58,368 KB
testcase_08 AC 51 ms
64,384 KB
testcase_09 AC 52 ms
64,512 KB
testcase_10 AC 51 ms
63,616 KB
testcase_11 AC 212 ms
98,816 KB
testcase_12 AC 187 ms
101,632 KB
testcase_13 AC 192 ms
93,696 KB
testcase_14 AC 160 ms
90,624 KB
testcase_15 AC 179 ms
99,328 KB
testcase_16 AC 211 ms
104,960 KB
testcase_17 AC 221 ms
105,088 KB
testcase_18 AC 225 ms
105,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.buffer.readline

N, Q = map(int, input().split())
A = tuple(map(int, input().split()))

stk = []
doubling = [[None] * N for _ in range(N.bit_length())]
for i, a in enumerate(A):
    while stk and stk[-1][1] <= a:
        j, b = stk.pop()
        doubling[0][j] = i
    stk.append((i, a))
for k in range(N.bit_length() - 1):
    for i in range(N):
        if doubling[k][i] is not None:
            doubling[k + 1][i] = doubling[k][doubling[k][i]]

for _ in range(Q):
    _, L, R = map(int, input().split())
    L -= 1
    R -= 1
    ans = 1
    for k in range(N.bit_length() - 1, -1, -1):
        if doubling[k][L] is not None and doubling[k][L] <= R:
            L = doubling[k][L]
            ans += 1 << k
    print(ans)
0