結果

問題 No.1604 Swap Sort:ONE
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-04-26 18:29:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 501 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 76,796 KB
最終ジャッジ日時 2023-09-20 12:31:00
合計ジャッジ時間 3,898 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,124 KB
testcase_01 AC 78 ms
71,304 KB
testcase_02 AC 76 ms
71,416 KB
testcase_03 AC 77 ms
71,140 KB
testcase_04 AC 76 ms
71,128 KB
testcase_05 AC 88 ms
76,592 KB
testcase_06 AC 87 ms
76,660 KB
testcase_07 AC 89 ms
76,564 KB
testcase_08 AC 88 ms
76,620 KB
testcase_09 AC 88 ms
76,572 KB
testcase_10 AC 88 ms
76,324 KB
testcase_11 AC 89 ms
76,500 KB
testcase_12 AC 89 ms
76,584 KB
testcase_13 AC 87 ms
76,796 KB
testcase_14 AC 88 ms
76,668 KB
testcase_15 AC 90 ms
76,672 KB
testcase_16 AC 89 ms
76,540 KB
testcase_17 AC 89 ms
76,536 KB
testcase_18 AC 89 ms
76,612 KB
testcase_19 AC 91 ms
76,384 KB
testcase_20 AC 90 ms
76,672 KB
testcase_21 AC 89 ms
76,616 KB
testcase_22 AC 89 ms
76,352 KB
testcase_23 AC 85 ms
75,728 KB
testcase_24 AC 83 ms
75,652 KB
testcase_25 AC 89 ms
76,352 KB
testcase_26 AC 87 ms
76,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

そのまま転倒数

"""

def bitadd(a,w,bit): #aにwを加える(1-origin)
 
    x = a
    while x <= (len(bit)-1):
        bit[x] += w
        x += x & (-1 * x)
 
def bitsum(a,bit): #ind 1~aまでの和を求める
 
    ret = 0
    x = a
    while x > 0:
        ret += bit[x]
        x -= x & (-1 * x)
    return ret


N = int(input())

BIT = [0] * (N+10)
a = list(map(int,input().split()))

ans = 0
for i in range(N):

    ans += i - bitsum(a[i],BIT)
    bitadd(a[i],1,BIT)

print (ans)
0