結果
問題 | No.1995 CHIKA Road |
ユーザー |
![]() |
提出日時 | 2022-07-01 21:59:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 401 ms / 2,000 ms |
コード長 | 1,223 bytes |
コンパイル時間 | 210 ms |
コンパイル使用メモリ | 82,216 KB |
実行使用メモリ | 189,184 KB |
最終ジャッジ日時 | 2024-11-26 04:59:02 |
合計ジャッジ時間 | 8,670 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
import sysinput = sys.stdin.readlineN,M=map(int,input().split())EX=[list(map(int,input().split())) for i in range(M)]LIST=[]for x,y in EX:LIST.append(x)LIST.append(y)LIST=sorted(set(LIST))D={LIST[i]:i for i in range(len(LIST))}E=[[] for i in range(len(LIST))]for x,y in EX:E[D[x]].append(D[y])def seg_function(x,y): # Segment treeで扱うfunctionreturn max(x,y)seg_el=1<<(len(LIST).bit_length()) # Segment treeの台の要素数SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化def update(n,x,seg_el): # A[n]をxへ更新i=n+seg_elSEG[i]=xi>>=1 # 子ノードへwhile i!=0:SEG[i]=seg_function(SEG[i*2],SEG[i*2+1])i>>=1def getvalues(l,r): # 区間[l,r)に関するseg_functionを調べるL=l+seg_elR=r+seg_elANS=0while L<R:if L & 1:ANS=seg_function(ANS , SEG[L])L+=1if R & 1:R-=1ANS=seg_function(ANS , SEG[R])L>>=1R>>=1return ANSfor i in range(len(LIST)):k=getvalues(0,i+1)for to in E[i]:update(to,k+1,seg_el)ANS=SEG[1]print(N*2-2-ANS)