結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー kurimupykurimupy
提出日時 2020-06-18 00:14:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 127 ms / 2,500 ms
コード長 688 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 9,612 KB
最終ジャッジ日時 2023-09-16 11:47:01
合計ジャッジ時間 1,736 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,780 KB
testcase_01 AC 15 ms
7,852 KB
testcase_02 AC 15 ms
7,804 KB
testcase_03 AC 14 ms
7,704 KB
testcase_04 AC 15 ms
7,820 KB
testcase_05 AC 16 ms
7,856 KB
testcase_06 AC 16 ms
7,848 KB
testcase_07 AC 18 ms
7,760 KB
testcase_08 AC 22 ms
8,192 KB
testcase_09 AC 15 ms
7,704 KB
testcase_10 AC 15 ms
7,760 KB
testcase_11 AC 127 ms
9,580 KB
testcase_12 AC 127 ms
9,612 KB
testcase_13 AC 15 ms
7,772 KB
testcase_14 AC 16 ms
7,844 KB
testcase_15 AC 16 ms
7,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)

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

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

    def get(self, i, j):
        return self.to_sum(j)-self.to_sum(i-1)


def count_inversion(lists):
    ans = 0
    N = len(lists)
    tree = BIT(N)
    for index, p in enumerate(lists):
        tree.add(p, 1)
        ans += index+1-tree.to_sum(p)
    return ans


N = int(input())
A = [int(input()) for i in range(N)]
ans = count_inversion(A)
print(ans)
0