結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー roarisroaris
提出日時 2019-09-18 21:39:34
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 119 ms / 2,500 ms
コード長 573 bytes
コンパイル時間 432 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 78,172 KB
最終ジャッジ日時 2023-09-23 02:57:07
合計ジャッジ時間 2,756 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,328 KB
testcase_01 AC 69 ms
71,352 KB
testcase_02 AC 69 ms
71,504 KB
testcase_03 AC 69 ms
71,304 KB
testcase_04 AC 71 ms
71,244 KB
testcase_05 AC 76 ms
75,688 KB
testcase_06 AC 82 ms
75,848 KB
testcase_07 AC 98 ms
76,740 KB
testcase_08 AC 101 ms
76,816 KB
testcase_09 AC 72 ms
71,484 KB
testcase_10 AC 72 ms
71,348 KB
testcase_11 AC 119 ms
78,136 KB
testcase_12 AC 116 ms
78,172 KB
testcase_13 AC 71 ms
71,572 KB
testcase_14 AC 71 ms
71,336 KB
testcase_15 AC 71 ms
71,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class fenwick_tree:
    def __init__(self, n):
        self.n = n
        #x, a1, a2, ..., an
        self.arr = [0] * (n+1)
    
    def add(self, i, x): #1_indexed
        while i <= self.n:
            self.arr[i] += x
            i += i & -i
    
    def query(self, i): #a1 + a2 + ... + ai
        res = 0
        while i > 0:
            res += self.arr[i]
            i -= i & -i
        return res

N = int(input())
M = [int(input()) for _ in range(N)]
ft = fenwick_tree(N)
ans = 0

for i in range(N):
    ans += i - ft.query(M[i]-1)
    ft.add(M[i], 1)

print(ans)
0