結果

問題 No.992 最長増加部分列の数え上げ
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-02-14 23:31:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 547 ms / 2,000 ms
コード長 1,035 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 175,716 KB
最終ジャッジ日時 2024-04-16 02:59:43
合計ジャッジ時間 15,893 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
52,096 KB
testcase_01 AC 45 ms
52,096 KB
testcase_02 AC 41 ms
51,968 KB
testcase_03 AC 41 ms
51,968 KB
testcase_04 AC 212 ms
115,584 KB
testcase_05 AC 183 ms
105,984 KB
testcase_06 AC 266 ms
125,824 KB
testcase_07 AC 211 ms
110,336 KB
testcase_08 AC 147 ms
91,776 KB
testcase_09 AC 215 ms
110,720 KB
testcase_10 AC 247 ms
125,824 KB
testcase_11 AC 307 ms
130,688 KB
testcase_12 AC 124 ms
85,376 KB
testcase_13 AC 204 ms
109,952 KB
testcase_14 AC 199 ms
110,080 KB
testcase_15 AC 124 ms
86,016 KB
testcase_16 AC 466 ms
146,800 KB
testcase_17 AC 141 ms
91,904 KB
testcase_18 AC 193 ms
109,824 KB
testcase_19 AC 310 ms
130,432 KB
testcase_20 AC 502 ms
174,940 KB
testcase_21 AC 547 ms
174,696 KB
testcase_22 AC 521 ms
175,068 KB
testcase_23 AC 495 ms
174,928 KB
testcase_24 AC 540 ms
174,680 KB
testcase_25 AC 538 ms
175,716 KB
testcase_26 AC 534 ms
174,812 KB
testcase_27 AC 536 ms
174,808 KB
testcase_28 AC 535 ms
175,068 KB
testcase_29 AC 526 ms
174,808 KB
testcase_30 AC 320 ms
167,480 KB
testcase_31 AC 317 ms
167,484 KB
testcase_32 AC 318 ms
167,880 KB
testcase_33 AC 319 ms
167,108 KB
testcase_34 AC 322 ms
167,152 KB
testcase_35 AC 316 ms
165,952 KB
testcase_36 AC 315 ms
166,336 KB
testcase_37 AC 314 ms
166,076 KB
testcase_38 AC 317 ms
165,944 KB
testcase_39 AC 315 ms
166,080 KB
testcase_40 AC 317 ms
145,636 KB
testcase_41 AC 314 ms
145,764 KB
testcase_42 AC 328 ms
146,148 KB
testcase_43 AC 319 ms
145,904 KB
testcase_44 AC 315 ms
145,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10**9+7
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [(0, 0) for _ in range(n+1)]
        self.tree[0] = (0, 1)
  
    def sum(self, i):
        s = (0, 1)
        while i > 0:
            if s[0] == self.tree[i][0]:
                s = (s[0], (self.tree[i][1] + s[1])%mod)
            elif s[0] < self.tree[i][0]:
                s = self.tree[i]
            i -= i & -i
        return s
  
    def add(self, i, x):
        while i <= self.size:
            if x[0] == self.tree[i][0]:
                self.tree[i] = (x[0], (self.tree[i][1] + x[1])%mod)
            elif x[0] > self.tree[i][0]:
                self.tree[i] = (x[0], x[1])
            i += i & -i

N, = map(int, input().split())
bs = list(map(int, input().split()))
ids = sorted(list(set(bs)))
x2i = dict()
for i, x in enumerate(ids):
    i += 1
    x2i[x] = i
As = [x2i[b] for b in bs]
 
#print(As)
bit = Bit(N)
for a in As:
    a0, co = bit.sum(a-1)
#    print(a, a0, co)
    bit.add(a, (a0+1, co))
print(bit.sum(N)[1]%mod)

0