結果
| 問題 |
No.3238 Shadow
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2025-08-15 23:02:45 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 407 ms / 2,000 ms |
| コード長 | 1,793 bytes |
| コンパイル時間 | 174 ms |
| コンパイル使用メモリ | 82,172 KB |
| 実行使用メモリ | 109,620 KB |
| 最終ジャッジ日時 | 2025-08-15 23:03:30 |
| 合計ジャッジ時間 | 4,933 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
import sys
input = sys.stdin.readline
N=int(input())
A=list(map(int,input().split()))
def seg_function(x,y): # Segment treeで扱うfunction
return min(x,y)
seg_el=1<<(N.bit_length()) # Segment treeの台の要素数
SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
for i in range(N): # Aを対応する箇所へupdate
SEG[i+seg_el]=A[i]
for i in range(seg_el-1,0,-1): # 親の部分もupdate
SEG[i]=seg_function(SEG[i*2],SEG[i*2+1])
def update(n,x,seg_el): # A[n]をxへ更新
i=n+seg_el
SEG[i]=x
i>>=1 # 子ノードへ
while i!=0:
SEG[i]=seg_function(SEG[i*2],SEG[i*2+1])
i>>=1
def getvalues(l,r): # 区間[l,r)に関するseg_functionを調べる
L=l+seg_el
R=r+seg_el
ANS1=1<<60
ANS2=1<<60
while L<R:
if L & 1:
ANS1=seg_function(ANS1, SEG[L])
L+=1
if R & 1:
R-=1
ANS2=seg_function(SEG[R], ANS2)
L>>=1
R>>=1
return seg_function(ANS1, ANS2)
def bisect_on_SEG(l,x):
L=l+seg_el
R=seg_el*2-1
while L<R:
if SEG[L]<x:
break
if L & 1:
L+=1
L>>=1
R>>=1
if SEG[L]>=x:
return N
while L<seg_el:
if SEG[L*2]<x:
L=L*2
else:
L=L*2+1
return L-seg_el
while True:
ANSX=1<<60
ANSY=1<<60
NOW=1<<30
l=0
while True:
k=bisect_on_SEG(l,NOW)
if k>=len(A) or A[k]>N:
break
else:
ANSX=min(ANSX,k+1)
ANSY=min(ANSY,A[k])
update(k,1<<60,seg_el)
NOW=A[k]
l=k+1
if ANSX>N:
break
print(ANSX,ANSY)
titia