結果

問題 No.930 数列圧縮
ユーザー AEnAEn
提出日時 2023-01-19 23:32:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 1,170 bytes
コンパイル時間 606 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 92,400 KB
最終ジャッジ日時 2023-09-04 18:03:04
合計ジャッジ時間 6,199 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,468 KB
testcase_01 AC 70 ms
71,196 KB
testcase_02 AC 72 ms
71,128 KB
testcase_03 AC 73 ms
75,464 KB
testcase_04 AC 77 ms
75,620 KB
testcase_05 AC 92 ms
77,408 KB
testcase_06 AC 77 ms
75,868 KB
testcase_07 AC 94 ms
78,092 KB
testcase_08 AC 157 ms
87,024 KB
testcase_09 AC 152 ms
88,412 KB
testcase_10 AC 147 ms
86,536 KB
testcase_11 AC 157 ms
86,960 KB
testcase_12 AC 169 ms
90,120 KB
testcase_13 AC 109 ms
84,520 KB
testcase_14 AC 114 ms
85,204 KB
testcase_15 AC 157 ms
92,064 KB
testcase_16 AC 174 ms
92,072 KB
testcase_17 AC 185 ms
92,332 KB
testcase_18 AC 173 ms
92,400 KB
testcase_19 AC 187 ms
92,072 KB
testcase_20 AC 190 ms
91,996 KB
testcase_21 AC 188 ms
92,308 KB
testcase_22 AC 70 ms
70,956 KB
testcase_23 AC 176 ms
92,280 KB
testcase_24 AC 70 ms
71,408 KB
testcase_25 AC 68 ms
71,476 KB
testcase_26 AC 70 ms
71,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Binary_Indexed_Tree:
    def __init__(self, n) -> None:
        self._n = n
        self.data = [0] * (n+1)
        self.depth = n.bit_length()

    def add(self, p, x) -> None:
        """任意の要素ai←ai+xを行う O(logn)"""
        assert 0 <= p < self._n
        p += 1
        while p <= self._n:
            self.data[p-1] += x
            p += p & (-p)
    
    def sum(self, l, r) -> int:
        """区間[l,r)で計算"""
        assert 0 <= l <= r <= self._n
        return self._sum(r) - self._sum(l)
    
    def _sum(self, d) -> int:
        sm = 0
        while d > 0:
            sm += self.data[d-1]
            d -= d & (-d)
        return sm

N = int(input())
A = list(map(int, input().split()))

if A[-1]==1:
    print('No')
    exit()

BIT = Binary_Indexed_Tree(N+5)
posi = [-1]*(N+1)
for i in range(N):
    BIT.add(i,1)
    posi[A[i]] = i
n = N
num = A[-1]
ans = []
while n>num:
    p = posi[n]
    sm = BIT._sum(p)
    if sm>0:
        BIT.add(p,-1)
        ans.append(n)
        n -= 1
    else:
        print('No')
        exit()

for i in range(N-2,-1,-1):
    if BIT.sum(i,i+1)>0:
        ans.append(A[i])
print('Yes')
print(*ans)
0