結果
| 問題 |
No.3305 Shift Sort
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2025-10-23 02:17:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 610 ms / 2,000 ms |
| コード長 | 892 bytes |
| コンパイル時間 | 272 ms |
| コンパイル使用メモリ | 82,324 KB |
| 実行使用メモリ | 176,284 KB |
| 最終ジャッジ日時 | 2025-10-23 02:17:32 |
| 合計ジャッジ時間 | 15,795 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
import sys
input = sys.stdin.readline
N,Q0=map(int,input().split())
A=list(map(int,input().split()))
TO=[-1]*N
Q=[]
for i in range(N):
a=A[i]
while Q and Q[-1][0]<a:
c,ind=Q.pop()
TO[ind]=i
Q.append((a,i))
# (通常の)ダブリングにおけるリスト作り
DOUBLING=[TO]
for i in range(60):
X=[-1]*len(A)
for j in range(len(A)):
X[j]=DOUBLING[-1][DOUBLING[-1][j]]
DOUBLING.append(X)
for tests in range(Q0):
x,y=map(int,input().split())
ALL=y-x
x-=1
y-=1
ANS=0
# y以下の範囲で何歩進めるか?
while x<=y:
for i in range(60):
if DOUBLING[i][x]==-1 or DOUBLING[i][x]>y:
walk=i-1
break
if walk==-1:
break
else:
ANS+=2**walk
x=DOUBLING[i-1][x]
print(ALL-ANS)
titia