結果
| 問題 |
No.878 Range High-Element Query
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2024-06-13 00:47:05 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 289 ms / 2,000 ms |
| コード長 | 692 bytes |
| コンパイル時間 | 1,667 ms |
| コンパイル使用メモリ | 82,060 KB |
| 実行使用メモリ | 112,468 KB |
| 最終ジャッジ日時 | 2024-06-13 00:47:11 |
| 合計ジャッジ時間 | 5,705 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
import sys
input = sys.stdin.readline
N,Q=map(int,input().split())
A=list(map(int,input().split()))
D=[N+1]*N
QU=[]
for i in range(N):
#print(QU)
a=A[i]
while QU and QU[-1][0]<a:
x,ind=QU.pop()
D[ind]=i
QU.append((a,i))
D=[D]
for i in range(31):
X=[N+1]*N
for j in range(N):
if D[-1][j]!=N+1:
X[j]=D[-1][D[-1][j]]
D.append(X)
for i in range(Q):
x,l,r=map(int,input().split())
now=l-1
ANS=0
while now<r:
for i in range(30,-1,-1):
if D[i][now]<r:
now=D[i][now]
ANS+=(1<<i)
break
else:
break
print(ANS+1)
titia