結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,856 KB
testcase_01 AC 17 ms
7,912 KB
testcase_02 AC 16 ms
7,856 KB
testcase_03 AC 17 ms
8,380 KB
testcase_04 AC 18 ms
8,400 KB
testcase_05 AC 19 ms
8,308 KB
testcase_06 AC 19 ms
8,248 KB
testcase_07 AC 1,861 ms
54,984 KB
testcase_08 TLE -
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます

ソースコード

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]

M = max(Ac)
ct = [0] * (M + 1)
for c in Ac:
    ct[c] += 1
for i in range(1, M + 1):
    ct[i] += ct[i - 1]

bit = Bit(M)
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] - ct[p - 1] + (N - ct[p])
print(*ans, sep='\n')
0