結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー hedwig100hedwig100
提出日時 2020-05-09 11:00:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 89 ms / 2,500 ms
コード長 734 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 9,708 KB
最終ジャッジ日時 2023-09-18 17:44:19
合計ジャッジ時間 2,232 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,764 KB
testcase_01 AC 16 ms
7,860 KB
testcase_02 AC 16 ms
7,812 KB
testcase_03 AC 15 ms
7,852 KB
testcase_04 AC 16 ms
7,804 KB
testcase_05 AC 16 ms
7,780 KB
testcase_06 AC 17 ms
7,808 KB
testcase_07 AC 18 ms
7,868 KB
testcase_08 AC 20 ms
8,308 KB
testcase_09 AC 16 ms
7,880 KB
testcase_10 AC 16 ms
7,780 KB
testcase_11 AC 89 ms
9,636 KB
testcase_12 AC 89 ms
9,708 KB
testcase_13 AC 16 ms
7,776 KB
testcase_14 AC 16 ms
7,852 KB
testcase_15 AC 17 ms
7,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(100000000)
input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = 10 ** 15

class BinaryIndexedTree():

    def __init__(self,init_val):
        self.bit = [0] + init_val
        self.n  = len(init_val)

    def sum(self,i):
        ret = 0
        while i > 0:
            ret += self.bit[i]
            i -= (i & -i)
        return ret
    
    def add(self,i,x):
        while i <= self.n:
            self.bit[i] += x
            i += (i & -i)

def main():
    N = int(input())
    M = [int(input()) for _ in range(N)]

    bit = BinaryIndexedTree([0] * N)
    ans = 0
    for i,m in enumerate(M):
        ans += i - bit.sum(m)
        bit.add(m,1)
    print(ans)
if __name__ == '__main__':
    main()
0