結果
問題 | No.992 最長増加部分列の数え上げ |
ユーザー |
![]() |
提出日時 | 2020-03-25 14:05:58 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,268 bytes |
コンパイル時間 | 365 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 72,484 KB |
最終ジャッジ日時 | 2025-01-01 20:41:37 |
合計ジャッジ時間 | 48,156 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 1 WA * 31 TLE * 10 |
ソースコード
#!/usr/bin/ python3.8import sysread = sys.stdin.buffer.readreadline = sys.stdin.buffer.readlinereadlines = sys.stdin.buffer.readlinesfrom bisect import bisect_leftimport itertoolsINF = 2 * 10 ** 9 + 10N = int(readline())A = (0,) + tuple(int(x) + 10 ** 9 + 1 for x in read().split())LIS = [0] * (N + 1)dp = [INF] * (N + 1)dp[0] = 0for n, x in enumerate(A[1:], 1):m = bisect_left(dp, x)dp[m] = xLIS[n] = mclass BinaryIndexedTree():def __init__(self, seq):self.size = len(seq)self.depth = self.size.bit_length()self.build(seq)def build(self, seq):data = seqsize = self.sizefor i, x in enumerate(data):j = i + (i & (-i))if j < size:data[j] += data[i]self.data = datadef __repr__(self):return self.data.__repr__()def get_sum(self, i):data = self.datas = 0while i:s += data[i]i -= i & -ireturn sdef add(self, i, x):data = self.datasize = self.sizewhile i < size:data[i] += xi += i & -idef find_kth_element(self, k):data = self.datasize = self.sizex, sx = 0, 0dx = 1 << (self.depth)for i in range(self.depth - 1, -1, -1):dx = (1 << i)if x + dx >= size:continuey = x + dxsy = sx + data[y]if sy < k:x, sx = y, syreturn x + 1M_LIS = max(LIS)LIS_cnt = [0] * (M_LIS + 1)for i, x in enumerate(LIS):LIS_cnt[x] += 1LIS_cnt = tuple(itertools.accumulate(LIS_cnt))keys = [(x << 32) + y for x, y in zip(LIS, A)]s_keys = sorted(keys)key_rank = {x: i for i, x in enumerate(s_keys)}bit = BinaryIndexedTree([0] * (N + 1)) # key の値に対する数え上げを管理answer = 0for L, k, a in zip(LIS[1:], keys[1:], A[1:]):if L == 1:x = 1else:r_key = k - (1 << 32)right = bisect_left(s_keys, r_key) - 1left = LIS_cnt[L - 2]x = bit.get_sum(right) - bit.get_sum(left - 1)if L == M_LIS:answer += xelse:bit.add(key_rank[k], x)print(answer)