結果
| 問題 |
No.1604 Swap Sort:ONE
|
| コンテスト | |
| ユーザー |
👑 SPD_9X2
|
| 提出日時 | 2021-04-26 18:29:51 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 52 ms / 2,000 ms |
| コード長 | 501 bytes |
| コンパイル時間 | 293 ms |
| コンパイル使用メモリ | 82,448 KB |
| 実行使用メモリ | 67,564 KB |
| 最終ジャッジ日時 | 2024-07-06 07:51:08 |
| 合計ジャッジ時間 | 2,453 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
"""
そのまま転倒数
"""
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)
SPD_9X2