結果

問題 No.1604 Swap Sort:ONE
ユーザー 👑 timitimi
提出日時 2021-07-28 17:16:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 500 bytes
コンパイル時間 1,470 ms
コンパイル使用メモリ 86,744 KB
実行使用メモリ 76,672 KB
最終ジャッジ日時 2023-10-11 15:05:31
合計ジャッジ時間 5,660 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,140 KB
testcase_01 AC 70 ms
71,108 KB
testcase_02 AC 71 ms
71,108 KB
testcase_03 AC 70 ms
71,084 KB
testcase_04 AC 72 ms
70,764 KB
testcase_05 AC 88 ms
76,660 KB
testcase_06 AC 82 ms
76,172 KB
testcase_07 AC 81 ms
76,608 KB
testcase_08 AC 81 ms
76,604 KB
testcase_09 AC 81 ms
76,140 KB
testcase_10 AC 83 ms
76,584 KB
testcase_11 AC 81 ms
76,412 KB
testcase_12 AC 81 ms
76,548 KB
testcase_13 AC 82 ms
76,552 KB
testcase_14 AC 83 ms
76,508 KB
testcase_15 AC 82 ms
76,564 KB
testcase_16 AC 82 ms
76,132 KB
testcase_17 AC 82 ms
76,496 KB
testcase_18 AC 80 ms
76,436 KB
testcase_19 AC 82 ms
76,504 KB
testcase_20 AC 82 ms
76,548 KB
testcase_21 AC 81 ms
76,672 KB
testcase_22 AC 85 ms
76,520 KB
testcase_23 AC 78 ms
75,296 KB
testcase_24 AC 78 ms
75,900 KB
testcase_25 AC 84 ms
76,556 KB
testcase_26 AC 85 ms
76,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
A=list(map(int, input().split()))
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
  
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
  
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
ppp=A
bit=Bit(5001)
ans=0
 
for i, p in enumerate(ppp):
  bit.add(p, 1)
  ans += i + 1 - bit.sum(p)
 
print(ans)
0