結果

問題 No.992 最長増加部分列の数え上げ
ユーザー nehan_der_thal
提出日時 2020-02-14 23:18:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 841 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 82,168 KB
実行使用メモリ 109,876 KB
最終ジャッジ日時 2024-10-06 13:18:50
合計ジャッジ時間 8,553 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other WA * 1 RE * 36 TLE * 1 -- * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10**9+7
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [(0, 1) for _ in range(n+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())
As = map(int, input().split())
 
bit = Bit(N)
for a in As:
    a0, co = bit.sum(a-1)
    bit.add(a, (a0+1, co))
print(bit.sum(N)[1])

0