結果
| 問題 |
No.1188 レベルX門松列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-22 15:52:09 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 379 ms / 2,000 ms |
| コード長 | 1,170 bytes |
| コンパイル時間 | 217 ms |
| コンパイル使用メモリ | 82,400 KB |
| 実行使用メモリ | 126,720 KB |
| 最終ジャッジ日時 | 2024-10-15 10:01:14 |
| 合計ジャッジ時間 | 5,723 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
# Binary Indexed Tree (Fenwick Tree)
# Binary Indexed Tree (Fenwick Tree)
class BIT_max:
def __init__(self, n):
self.n = n
self.bit = [0]*(n+1)
self.el = [0]*(n+1)
def query(self, i):
s = 0
while i > 0:
s = max(s,self.bit[i])
i -= i & -i
return s
def update(self, i, x):
# assert i > 0
self.el[i] = max(self.el[i],x)
while i <= self.n:
self.bit[i] = max(self.bit[i],x)
i += i & -i
N = int(input())
A = list(map(int, input().split()))
def compress(arr):
*XS, = set(arr)
XS.sort()
return {e: i+1 for i, e in enumerate(XS)}
tra = compress(A)
for i in range(N):
A[i] = tra[A[i]]
def calc(A,N):
bit = BIT_max(N)
lis1,lis2 = [0]*N,[0]*N
for i in range(N):
lis1[i] = bit.query(A[i]-1)
bit.update(A[i],lis1[i]+1)
bit = BIT_max(N)
for i in range(N-1,-1,-1):
lis2[i] = bit.query(A[i]-1)
bit.update(A[i],lis2[i]+1)
ans = 0
for i in range(N):
ans = max(ans, min(lis1[i],lis2[i]))
return ans
a = calc(A,N)
b = calc(list(map(lambda x:-x+N+1,A)),N)
print(max(a,b))