結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
コンテスト
ユーザー kurimupy
提出日時 2020-06-18 00:14:20
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 170 ms / 2,500 ms
コード長 688 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 760 ms
コンパイル使用メモリ 20,824 KB
実行使用メモリ 15,708 KB
最終ジャッジ日時 2026-03-24 20:45:21
合計ジャッジ時間 3,102 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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