結果

問題 No.992 最長増加部分列の数え上げ
ユーザー qqqqqqqqqq
提出日時 2020-02-18 21:11:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,303 ms / 2,000 ms
コード長 1,632 bytes
コンパイル時間 398 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 139,504 KB
最終ジャッジ日時 2024-04-16 04:15:31
合計ジャッジ時間 31,123 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,480 KB
testcase_01 AC 42 ms
52,480 KB
testcase_02 AC 42 ms
52,480 KB
testcase_03 AC 43 ms
52,224 KB
testcase_04 AC 486 ms
99,712 KB
testcase_05 AC 364 ms
95,488 KB
testcase_06 AC 573 ms
100,992 KB
testcase_07 AC 421 ms
97,920 KB
testcase_08 AC 260 ms
88,372 KB
testcase_09 AC 441 ms
97,920 KB
testcase_10 AC 565 ms
101,120 KB
testcase_11 AC 690 ms
102,628 KB
testcase_12 AC 196 ms
82,912 KB
testcase_13 AC 414 ms
98,048 KB
testcase_14 AC 415 ms
97,828 KB
testcase_15 AC 203 ms
83,584 KB
testcase_16 AC 1,113 ms
116,736 KB
testcase_17 AC 263 ms
88,320 KB
testcase_18 AC 408 ms
97,920 KB
testcase_19 AC 721 ms
101,964 KB
testcase_20 AC 1,233 ms
138,812 KB
testcase_21 AC 1,205 ms
138,772 KB
testcase_22 AC 1,260 ms
139,160 KB
testcase_23 AC 1,258 ms
139,160 KB
testcase_24 AC 1,198 ms
139,172 KB
testcase_25 AC 1,248 ms
139,420 KB
testcase_26 AC 1,303 ms
138,652 KB
testcase_27 AC 1,214 ms
138,736 KB
testcase_28 AC 1,225 ms
139,156 KB
testcase_29 AC 1,229 ms
139,160 KB
testcase_30 AC 632 ms
138,892 KB
testcase_31 AC 612 ms
138,544 KB
testcase_32 AC 624 ms
138,504 KB
testcase_33 AC 628 ms
138,520 KB
testcase_34 AC 622 ms
138,916 KB
testcase_35 AC 448 ms
138,380 KB
testcase_36 AC 447 ms
138,376 KB
testcase_37 AC 445 ms
138,536 KB
testcase_38 AC 453 ms
138,384 KB
testcase_39 AC 448 ms
138,884 KB
testcase_40 AC 627 ms
139,504 KB
testcase_41 AC 633 ms
139,408 KB
testcase_42 AC 632 ms
138,896 KB
testcase_43 AC 658 ms
139,504 KB
testcase_44 AC 654 ms
139,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().strip()

mod = 10**9+7

class RangeMinimumQuery:
    def __init__(self, n, F=min, e=float("inf"), fill=None):
        self.n = n
        self.n0 = 2**(n-1).bit_length()
        self.F = F
        self.e = e
        if fill is None:
            fill = e
        self.data = [fill]*(2*self.n0)

    def construct(self, a):
        for i, x in enumerate(a):
            self.data[i+self.n0-1] = x
        for i in range(self.n0-2, -1, -1):
            self.data[i] = self.F(self.data[2*i+1], self.data[2*i+2])

    def query(self, l,r):
        l += self.n0
        r += self.n0
        res = self.e
        while l < r:
            if r&1:
                r -= 1
                res = self.F(res, self.data[r-1])
            if l&1:
                res = self.F(res, self.data[l-1])
                l += 1
            l >>=1
            r >>=1
        return res

    def update(self, i, x):
        i += self.n0-1
        self.data[i] = x
        while i:
            i = ~-i//2
            self.data[i] = self.F(self.data[2*i+1], self.data[2*i+2])

def updater(a,b):
    if a[0] == b[0]:
        return (a[0], (a[1]+b[1])%mod)
    elif a[0] > b[0]:
        return a
    else:
        return b

n = int(input())
a = list(map(int, input().split()))

seg = RangeMinimumQuery(n, updater, (0,0), None)

b = [[ai, i] for i, ai in enumerate(a)]
b.sort(key=lambda x: (x[0], -x[1]))

for i in range(n):
    _, j = b[i]
    tmp = seg.query(0, j)
    if tmp == (0,0):
        seg.update(j, (tmp[0]+1, 1))
    else:
        seg.update(j, (tmp[0]+1, tmp[1]))

ans = seg.query(0, n)[1]
print(ans)
0