結果

問題 No.1604 Swap Sort:ONE
コンテスト
ユーザー SPD_9X2
提出日時 2021-04-26 18:29:51
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 68 ms / 2,000 ms
+ 792µs
コード長 501 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 235 ms
コンパイル使用メモリ 96,488 KB
実行使用メモリ 83,840 KB
最終ジャッジ日時 2026-08-09 07:10:49
合計ジャッジ時間 3,867 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

"""

そのまま転倒数

"""

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