結果

問題 No.694 square1001 and Permutation 3
ユーザー H3PO4H3PO4
提出日時 2020-11-30 09:13:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 680 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 117,596 KB
最終ジャッジ日時 2023-10-11 02:44:00
合計ジャッジ時間 12,085 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 18 ms
8,300 KB
testcase_06 AC 18 ms
8,436 KB
testcase_07 WA -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 WA -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 AC 15 ms
7,864 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


N = int(input())
A = [int(input()) for _ in range(N)]
d = {x: i for i, x in enumerate(sorted(list(set(A))), 1)}
Ac = [d[a] for a in A]
bit = Bit(max(Ac))
ans = [0] * N

for i, p in enumerate(Ac):
    bit.add(p, 1)
    ans[0] += i + 1 - bit.sum(p)
for i, p in enumerate(Ac[:-1]):
    ans[i + 1] = ans[i] - (p - 1) + (N - p)
print(*ans, sep='\n')
0