結果

問題 No.930 数列圧縮
ユーザー 👑 tamatotamato
提出日時 2019-11-22 22:16:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,881 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 95,128 KB
最終ジャッジ日時 2024-04-19 11:45:39
合計ジャッジ時間 4,048 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
52,352 KB
testcase_01 AC 35 ms
52,352 KB
testcase_02 AC 35 ms
52,736 KB
testcase_03 AC 34 ms
53,120 KB
testcase_04 AC 40 ms
60,032 KB
testcase_05 AC 53 ms
67,968 KB
testcase_06 AC 43 ms
61,184 KB
testcase_07 AC 63 ms
76,800 KB
testcase_08 AC 109 ms
91,300 KB
testcase_09 AC 145 ms
90,160 KB
testcase_10 AC 112 ms
88,760 KB
testcase_11 AC 110 ms
89,416 KB
testcase_12 AC 118 ms
92,224 KB
testcase_13 AC 97 ms
85,212 KB
testcase_14 AC 93 ms
85,620 KB
testcase_15 AC 107 ms
94,888 KB
testcase_16 AC 134 ms
94,700 KB
testcase_17 AC 150 ms
94,692 KB
testcase_18 AC 182 ms
94,124 KB
testcase_19 AC 141 ms
94,692 KB
testcase_20 AC 133 ms
91,952 KB
testcase_21 AC 127 ms
95,128 KB
testcase_22 AC 34 ms
52,224 KB
testcase_23 AC 101 ms
94,948 KB
testcase_24 AC 32 ms
52,608 KB
testcase_25 AC 32 ms
52,096 KB
testcase_26 AC 32 ms
52,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    # i+1番目からR番目まで足すとt以上となるような最小のRを返す
    def bisect_plus(self, i, t):
        L = i
        R = self.size
        R_prev = R
        sum_i = self.sum(i)
        while True:
            range_sum = self.sum(R) - sum_i
            if range_sum < t:
                if R == self.size:
                    return self.size + 1
                L, R = R, R_prev
            else:
                R_prev = R
                R = (L + R + 1) // 2
                if R == R_prev:
                    return R

    # L番目からi-1番目まで足すとt以上となるような最小のLを返す
    def bisect_minus(self, i, t):
        L = 1
        R = i
        L_prev = L
        sum_i = self.sum(i - 1)
        while True:
            range_sum = sum_i - self.sum(L - 1)
            if range_sum < t:
                if L == 1:
                    return 0
                L, R = L_prev, L
            else:
                L_prev = L
                L = (L + R) // 2
                if L == L_prev:
                    return L


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

seen = Bit(N)
pos = {}
for i, a in enumerate(A):
    seen.add(a, 1)
    pos[a] = i+1
ans = []
for i in range(1, N):
    if seen.sum(pos[i]) == 1:
        for j in range(N):
            if A[j] > i:
                ans.append(A[j])
        break
    elif seen.sum(N) - seen.sum(pos[i]) == 0:
        print('No')
        exit()
    else:
        ans.append(i)
        seen.add(pos[i], -1)

print('Yes')
print(*ans)
0