結果

問題 No.2665 Minimize Inversions of Deque
ユーザー ニックネームニックネーム
提出日時 2024-03-08 21:22:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 823 ms / 2,000 ms
コード長 577 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 33,508 KB
最終ジャッジ日時 2024-03-08 21:22:28
合計ジャッジ時間 21,785 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,112 KB
testcase_01 AC 621 ms
10,112 KB
testcase_02 AC 567 ms
10,112 KB
testcase_03 AC 575 ms
10,112 KB
testcase_04 AC 578 ms
10,112 KB
testcase_05 AC 591 ms
10,112 KB
testcase_06 AC 561 ms
10,112 KB
testcase_07 AC 584 ms
10,112 KB
testcase_08 AC 570 ms
10,112 KB
testcase_09 AC 606 ms
10,112 KB
testcase_10 AC 558 ms
10,112 KB
testcase_11 AC 590 ms
10,112 KB
testcase_12 AC 575 ms
10,112 KB
testcase_13 AC 568 ms
10,112 KB
testcase_14 AC 565 ms
10,112 KB
testcase_15 AC 562 ms
10,112 KB
testcase_16 AC 572 ms
10,112 KB
testcase_17 AC 558 ms
10,112 KB
testcase_18 AC 568 ms
10,112 KB
testcase_19 AC 102 ms
10,112 KB
testcase_20 AC 41 ms
10,496 KB
testcase_21 AC 42 ms
10,368 KB
testcase_22 AC 42 ms
10,496 KB
testcase_23 AC 42 ms
10,752 KB
testcase_24 AC 42 ms
10,624 KB
testcase_25 AC 42 ms
10,624 KB
testcase_26 AC 42 ms
10,496 KB
testcase_27 AC 41 ms
10,496 KB
testcase_28 AC 43 ms
10,624 KB
testcase_29 AC 46 ms
10,752 KB
testcase_30 AC 802 ms
30,972 KB
testcase_31 AC 725 ms
20,108 KB
testcase_32 AC 745 ms
20,208 KB
testcase_33 AC 804 ms
27,172 KB
testcase_34 AC 737 ms
17,188 KB
testcase_35 AC 791 ms
33,508 KB
testcase_36 AC 808 ms
33,508 KB
testcase_37 AC 751 ms
19,736 KB
testcase_38 AC 769 ms
27,088 KB
testcase_39 AC 823 ms
33,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT:
    def __init__(self,n):
        self.n = n; self.k = [0]*(n+1)
    def a(self,i,x):
        while i<=self.n: self.k[i] += x; i += i&-i
    def s(self,i):
        t = 0
        while i>0: t += self.k[i]; i -= i&-i
        return t
from collections import deque
for _ in range(int(input())):
    n = int(input()); bit = BIT(n); x = 0; dq = deque()
    for i,v in enumerate(map(int,input().split())):
        c = bit.s(v); bit.a(v,1)
        if c<i-c or c==i-c and dq and v<dq[0]: x += c; dq.appendleft(v)
        else: x += i-c; dq.append(v)
    print(x); print(*dq)
0