結果
問題 | No.878 Range High-Element Query |
ユーザー |
👑 |
提出日時 | 2022-10-30 16:21:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 453 ms / 2,000 ms |
コード長 | 592 bytes |
コンパイル時間 | 281 ms |
コンパイル使用メモリ | 82,336 KB |
実行使用メモリ | 112,260 KB |
最終ジャッジ日時 | 2024-07-07 07:35:50 |
合計ジャッジ時間 | 5,800 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
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 -= 1r -= 1ans = 1for i in range(29, -1, -1):if nex[i][l] <= r:l = nex[i][l]ans += 1 << iprint(ans)