結果

問題 No.694 square1001 and Permutation 3
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-10-01 10:52:59
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 604 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 86,856 KB
実行使用メモリ 89,640 KB
最終ジャッジ日時 2023-09-25 21:23:29
合計ジャッジ時間 7,489 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 WA -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 WA -
testcase_08 WA -
testcase_09 RE -
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 70 ms
71,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BinaryIndexedTree():
    def __init__(self, n):
        self.n = n
        self.BIT = [0] * (self.n + 1)
 
    def add(self, i, x):
        while i <= self.n:
            self.BIT[i] += x
            i += i & -i
 
    def query(self, i):
        res = 0
        while i > 0:
            res += self.BIT[i]
            i -= i & -i
        return res

n = int(input())
a = [int(input()) - 1 for i in range(n)]
ans = 0
BIT = BinaryIndexedTree(n)
for i in range(n):
    ans += i - BIT.query(a[i] + 1)
    BIT.add(a[i] + 1, 1)
print(ans)
for i in range(n - 1):
    ans += n - 2 * a[i] - 1
    print(ans)
0