結果

問題 No.1619 Coccinellidae
ユーザー tktk_snsntktk_snsn
提出日時 2021-09-20 22:28:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 809 ms / 2,000 ms
コード長 1,297 bytes
コンパイル時間 606 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 20,124 KB
最終ジャッジ日時 2023-09-15 21:57:16
合計ジャッジ時間 8,385 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,924 KB
testcase_01 AC 669 ms
17,216 KB
testcase_02 AC 809 ms
19,268 KB
testcase_03 AC 15 ms
8,184 KB
testcase_04 AC 809 ms
20,124 KB
testcase_05 AC 457 ms
14,204 KB
testcase_06 AC 19 ms
8,168 KB
testcase_07 AC 465 ms
15,364 KB
testcase_08 AC 429 ms
15,008 KB
testcase_09 AC 16 ms
8,256 KB
testcase_10 AC 394 ms
14,404 KB
testcase_11 AC 566 ms
16,428 KB
testcase_12 AC 15 ms
8,172 KB
testcase_13 AC 767 ms
19,296 KB
testcase_14 AC 801 ms
18,440 KB
testcase_15 AC 16 ms
7,972 KB
testcase_16 AC 15 ms
8,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class fenwick_tree(object):
    def __init__(self, n):
        self.n = n
        self.log = n.bit_length()
        self.data = [0] * n

    def __sum(self, r):
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s

    def add(self, p, x):
        """ a[p] += xを行う"""
        p += 1
        while p <= self.n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, l, r):
        """a[l] + a[l+1] + .. + a[r-1]を返す"""
        return self.__sum(r) - self.__sum(l)

    def lower_bound(self, x):
        """a[0] + a[1] + .. a[i] >= x となる最小のiを返す"""
        if x <= 0:
            return -1
        i = 0
        k = 1 << self.log
        while k:
            if i + k <= self.n and self.data[i + k - 1] < x:
                x -= self.data[i + k - 1]
                i += k
            k >>= 1
        return i


N, M, K = map(int, input().split())
elem = list(range(N-1))
elem.append(M - sum(elem))
elem.reverse()

pos = [0] * N
for i in range(N):
    d = min(K, i)
    K -= d
    pos[i] = d

bit = fenwick_tree(N)
for i in range(N):
    bit.add(i, 1)

ans = [0] * N
for i in reversed(range(N)):
    x = bit.lower_bound(pos[i]+1)
    bit.add(x, -1)
    ans[x] = elem[i]

print(*ans, sep="\n")
0