結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー rookzenorookzeno
提出日時 2018-10-06 00:24:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 170 ms / 2,500 ms
コード長 409 bytes
コンパイル時間 138 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-04-20 18:02:01
合計ジャッジ時間 1,445 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,624 KB
testcase_01 AC 26 ms
10,880 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 AC 26 ms
10,752 KB
testcase_04 AC 27 ms
10,752 KB
testcase_05 AC 27 ms
10,752 KB
testcase_06 AC 27 ms
10,752 KB
testcase_07 AC 31 ms
10,880 KB
testcase_08 AC 34 ms
10,624 KB
testcase_09 AC 26 ms
10,624 KB
testcase_10 AC 26 ms
10,752 KB
testcase_11 AC 166 ms
12,288 KB
testcase_12 AC 170 ms
12,288 KB
testcase_13 AC 27 ms
10,880 KB
testcase_14 AC 26 ms
10,752 KB
testcase_15 AC 26 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
src = []
for i in range(N):
    a = int(input())
    src.append(a)

bit = [0] * (N+1)
def bit_add(a,w):
    x = a
    while x <= N:
        bit[x] += w
        x += (x & -x)
 
def bit_sum(a):
    x = a
    ret = 0
    while x > 0:
        ret += bit[x]
        x -= (x & -x)
    return ret
 
ans = 0
for i in range(N-1,-1,-1):
    a = src[i]
    ans += bit_sum(a)
    bit_add(a,1)

print(ans)
0