結果

問題 No.878 Range High-Element Query
ユーザー 👑 rin204rin204
提出日時 2022-10-30 16:21:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 442 ms / 2,000 ms
コード長 592 bytes
コンパイル時間 1,782 ms
コンパイル使用メモリ 86,508 KB
実行使用メモリ 113,348 KB
最終ジャッジ日時 2023-09-21 13:48:27
合計ジャッジ時間 6,382 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,008 KB
testcase_01 AC 91 ms
76,628 KB
testcase_02 AC 95 ms
76,960 KB
testcase_03 AC 78 ms
75,976 KB
testcase_04 AC 89 ms
76,672 KB
testcase_05 AC 92 ms
76,776 KB
testcase_06 AC 79 ms
76,040 KB
testcase_07 AC 75 ms
75,904 KB
testcase_08 AC 91 ms
76,768 KB
testcase_09 AC 91 ms
76,916 KB
testcase_10 AC 89 ms
76,788 KB
testcase_11 AC 432 ms
105,240 KB
testcase_12 AC 311 ms
108,952 KB
testcase_13 AC 367 ms
99,804 KB
testcase_14 AC 289 ms
96,108 KB
testcase_15 AC 319 ms
105,832 KB
testcase_16 AC 413 ms
112,528 KB
testcase_17 AC 442 ms
113,348 KB
testcase_18 AC 439 ms
113,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, Q = map(int, input().split())
A = list(map(int, input().split()))

stack = [(n, 1 << 60)]
nex = [[n] * (n + 1) for _ in range(30)]
for i in range(n - 1, -1, -1):
    a = A[i]
    while stack[-1][1] < a:
        stack.pop()
    nex[0][i] = stack[-1][0]
    stack.append((i, a))

for i in range(1, 30):
    for j in range(n):
        nex[i][j] = nex[i - 1][nex[i - 1][j]]

for _ in range(Q):
    _, l, r = map(int, input().split())
    l -= 1
    r -= 1
    ans = 1
    for i in range(29, -1, -1):
        if nex[i][l] <= r:
            l = nex[i][l]
            ans += 1 << i
    print(ans)
0