結果

問題 No.992 最長増加部分列の数え上げ
ユーザー convexineqconvexineq
提出日時 2020-02-14 22:40:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,035 ms / 2,000 ms
コード長 1,739 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 106,368 KB
最終ジャッジ日時 2024-04-16 02:42:57
合計ジャッジ時間 26,118 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,352 KB
testcase_01 AC 44 ms
52,224 KB
testcase_02 AC 43 ms
52,480 KB
testcase_03 AC 43 ms
51,968 KB
testcase_04 AC 426 ms
91,904 KB
testcase_05 AC 325 ms
87,552 KB
testcase_06 AC 500 ms
96,896 KB
testcase_07 AC 365 ms
90,368 KB
testcase_08 AC 232 ms
83,072 KB
testcase_09 AC 365 ms
90,240 KB
testcase_10 AC 480 ms
96,768 KB
testcase_11 AC 580 ms
102,144 KB
testcase_12 AC 172 ms
80,000 KB
testcase_13 AC 344 ms
89,472 KB
testcase_14 AC 350 ms
90,240 KB
testcase_15 AC 187 ms
80,640 KB
testcase_16 AC 891 ms
104,320 KB
testcase_17 AC 228 ms
83,200 KB
testcase_18 AC 339 ms
89,472 KB
testcase_19 AC 582 ms
102,016 KB
testcase_20 AC 1,009 ms
105,728 KB
testcase_21 AC 1,035 ms
105,600 KB
testcase_22 AC 975 ms
105,984 KB
testcase_23 AC 967 ms
105,984 KB
testcase_24 AC 967 ms
105,472 KB
testcase_25 AC 1,000 ms
105,856 KB
testcase_26 AC 958 ms
105,856 KB
testcase_27 AC 963 ms
105,600 KB
testcase_28 AC 960 ms
105,728 KB
testcase_29 AC 1,023 ms
105,472 KB
testcase_30 AC 532 ms
106,368 KB
testcase_31 AC 536 ms
106,240 KB
testcase_32 AC 525 ms
105,728 KB
testcase_33 AC 524 ms
106,112 KB
testcase_34 AC 524 ms
106,240 KB
testcase_35 AC 382 ms
106,240 KB
testcase_36 AC 382 ms
105,856 KB
testcase_37 AC 384 ms
105,984 KB
testcase_38 AC 382 ms
105,856 KB
testcase_39 AC 384 ms
105,856 KB
testcase_40 AC 550 ms
106,368 KB
testcase_41 AC 548 ms
105,600 KB
testcase_42 AC 561 ms
105,984 KB
testcase_43 AC 566 ms
106,112 KB
testcase_44 AC 564 ms
106,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class segment_tree:
    def __init__(self, N, operator_M, e_M):
        self.op_M = operator_M
        self.e_M = e_M
        
        self.N0 = 1<<(N-1).bit_length()
        self.dat = [self.e_M]*(2*self.N0)
    
    # 長さNの配列 initial で初期化
    def build(self, initial):
        self.dat[self.N0:self.N0+len(initial)] = initial[:]
        for k in range(self.N0-1,0,-1):
            self.dat[k] = self.op_M(self.dat[2*k], self.dat[2*k+1])

    # a_k の値を x に更新
    def update(self,k,x):
        k += self.N0
        self.dat[k] = x
        k //= 2
        while k:
            self.dat[k] = self.op_M(self.dat[2*k], self.dat[2*k+1])
            k //= 2

    # 区間[L,R]をopでまとめる
    def query(self,L,R):
        L += self.N0; R += self.N0 + 1 
        sl = sr = self.e_M
        while L < R:
            if R & 1:
                R -= 1
                sr = self.op_M(self.dat[R],sr)
            if L & 1:
                sl = self.op_M(sl,self.dat[L])
                L += 1
            L >>= 1; R >>= 1
        return self.op_M(sl,sr)

    def get(self, k): #k番目の値を取得。query[k,k]と同じ
        return self.dat[k+self.N0]


# coding: utf-8
# Your code here!

import sys
readline = sys.stdin.readline
read = sys.stdin.read


# (length, num)
def op(X,Y):
    d,n = X
    e,m = Y
    if d < e:  return Y
    if d > e:  return X
    if d == e: return (d,(n+m)%1000000007)

n,*a = [int(i) for i in read().split()]
sa = sorted((ai,-i) for i,ai in enumerate(a))

seg = segment_tree(n, op, (0,0))

for v,i in sa:
    d,num = seg.query(0,-i)
    if d != 0:
        seg.update(-i,(d+1,num))
    else:
        seg.update(-i,(1,1))
    
    
#print(seg.dat)
print(seg.dat[1][1])
    







0