結果

問題 No.992 最長増加部分列の数え上げ
ユーザー titiatitia
提出日時 2020-03-25 06:40:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 888 ms / 2,000 ms
コード長 1,360 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 176,940 KB
最終ジャッジ日時 2023-08-30 09:24:03
合計ジャッジ時間 24,762 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,504 KB
testcase_01 AC 70 ms
71,416 KB
testcase_02 AC 71 ms
71,456 KB
testcase_03 AC 70 ms
71,388 KB
testcase_04 AC 405 ms
116,928 KB
testcase_05 AC 329 ms
107,080 KB
testcase_06 AC 441 ms
123,628 KB
testcase_07 AC 365 ms
112,368 KB
testcase_08 AC 246 ms
93,188 KB
testcase_09 AC 392 ms
112,672 KB
testcase_10 AC 473 ms
123,552 KB
testcase_11 AC 532 ms
116,492 KB
testcase_12 AC 200 ms
86,616 KB
testcase_13 AC 346 ms
111,980 KB
testcase_14 AC 368 ms
112,004 KB
testcase_15 AC 213 ms
87,372 KB
testcase_16 AC 807 ms
167,284 KB
testcase_17 AC 248 ms
93,188 KB
testcase_18 AC 370 ms
111,520 KB
testcase_19 AC 558 ms
116,556 KB
testcase_20 AC 809 ms
176,360 KB
testcase_21 AC 880 ms
176,408 KB
testcase_22 AC 856 ms
176,604 KB
testcase_23 AC 888 ms
176,380 KB
testcase_24 AC 882 ms
176,304 KB
testcase_25 AC 846 ms
176,372 KB
testcase_26 AC 879 ms
176,244 KB
testcase_27 AC 822 ms
176,336 KB
testcase_28 AC 869 ms
176,640 KB
testcase_29 AC 814 ms
176,940 KB
testcase_30 AC 436 ms
169,604 KB
testcase_31 AC 446 ms
169,704 KB
testcase_32 AC 438 ms
170,108 KB
testcase_33 AC 432 ms
169,228 KB
testcase_34 AC 441 ms
169,360 KB
testcase_35 AC 475 ms
168,536 KB
testcase_36 AC 479 ms
168,748 KB
testcase_37 AC 488 ms
168,132 KB
testcase_38 AC 483 ms
168,752 KB
testcase_39 AC 481 ms
167,940 KB
testcase_40 AC 447 ms
169,348 KB
testcase_41 AC 447 ms
169,808 KB
testcase_42 AC 449 ms
169,564 KB
testcase_43 AC 451 ms
169,984 KB
testcase_44 AC 444 ms
169,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
A=list(map(int,input().split()))
mod=10**9+7

compression_dict={a: ind+1 for ind, a in enumerate(sorted(set(A)))}
A=[compression_dict[a] for a in A]

def seg_function(x,y): # Segment treeで扱うfunction
    if x[0]==y[0]:
        return (x[0],x[1]+y[1])
    elif x[0]>y[0]:
        return x
    else:
        return y

seg_el=1<<(N.bit_length()) # Segment treeの台の要素数
SEG=[(-1,0)]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化

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
    ANS=(-1,0)

    while L<R:
        if L & 1:
            ANS=seg_function(ANS , SEG[L])
            L+=1

        if R & 1:
            R-=1
            ANS=seg_function(ANS , SEG[R])
        L>>=1
        R>>=1

    return ANS

update(0,(0,1),seg_el)

for a in A:

    y=getvalues(a,a+1)
    z=getvalues(0,a)

    #print(a,x,y)

    if z[0]<y[0]:
        update(a,(y[0],z[1]+y[1]),seg_el)
    else:
        update(a,(z[0]+1,z[1]),seg_el)

    #for i in range(7):
    #    print(getvalues(i,i+1),end=" ")
    #print()
    
print(getvalues(0,N+1)[1]%mod)
0