結果
| 問題 |
No.992 最長増加部分列の数え上げ
|
| ユーザー |
nehan_der_thal
|
| 提出日時 | 2020-02-14 23:31:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 444 ms / 2,000 ms |
| コード長 | 1,035 bytes |
| コンパイル時間 | 290 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 175,808 KB |
| 最終ジャッジ日時 | 2024-10-06 13:27:02 |
| 合計ジャッジ時間 | 13,500 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 |
ソースコード
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)
nehan_der_thal