結果
問題 |
No.878 Range High-Element Query
|
ユーザー |
![]() |
提出日時 | 2020-03-21 03:45:32 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 684 ms / 2,000 ms |
コード長 | 822 bytes |
コンパイル時間 | 451 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 34,736 KB |
最終ジャッジ日時 | 2024-12-16 07:29:48 |
合計ジャッジ時間 | 7,181 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, Q = map(int, readline().split()) A = [0] + list(map(int, readline().split())) + [N + 1] stack = [N + 1] next_high = [N + 1] * (N + 2) for n in range(N, -1, -1): x = A[n] while x > A[stack[-1]]: stack.pop() next_high[n] = stack[-1] stack.append(n) dp = [None] * 17 dp[0] = next_high for n in range(1, 17): prev = dp[n - 1] dp[n] = [prev[prev[i]] for i in range(N + 2)] def solve(): _, L, R = map(int, readline().split()) ret = 1 for n in range(16, -1, -1): m = dp[n][L] if m <= R: ret += 1 << n L = m return ret answers = (solve() for _ in range(Q)) print('\n'.join(map(str, answers)))