結果

問題 No.930 数列圧縮
ユーザー AEnAEn
提出日時 2023-01-19 23:30:35
言語 PyPy3
(7.3.15)
結果
OLE  
実行時間 -
コード長 1,155 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 108,176 KB
最終ジャッジ日時 2023-09-04 18:00:18
合計ジャッジ時間 6,868 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
75,956 KB
testcase_01 AC 68 ms
71,540 KB
testcase_02 AC 69 ms
71,552 KB
testcase_03 AC 74 ms
75,636 KB
testcase_04 AC 79 ms
75,828 KB
testcase_05 AC 94 ms
77,832 KB
testcase_06 OLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

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')

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