結果

問題 No.2665 Minimize Inversions of Deque
ユーザー 👑 p-adicp-adic
提出日時 2023-12-30 13:28:15
言語 cLay
(20240104-1)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 520 bytes
コンパイル時間 2,719 ms
コンパイル使用メモリ 179,088 KB
実行使用メモリ 29,376 KB
最終ジャッジ日時 2024-01-05 15:03:26
合計ジャッジ時間 6,295 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,488 KB
testcase_01 AC 27 ms
10,304 KB
testcase_02 AC 27 ms
10,176 KB
testcase_03 AC 27 ms
10,304 KB
testcase_04 AC 27 ms
10,304 KB
testcase_05 AC 27 ms
10,304 KB
testcase_06 AC 27 ms
10,304 KB
testcase_07 AC 27 ms
10,304 KB
testcase_08 AC 27 ms
10,304 KB
testcase_09 AC 28 ms
10,304 KB
testcase_10 AC 28 ms
10,304 KB
testcase_11 AC 27 ms
10,304 KB
testcase_12 AC 28 ms
10,304 KB
testcase_13 AC 27 ms
10,304 KB
testcase_14 AC 27 ms
10,304 KB
testcase_15 AC 28 ms
10,304 KB
testcase_16 AC 28 ms
10,304 KB
testcase_17 AC 28 ms
10,304 KB
testcase_18 AC 28 ms
10,304 KB
testcase_19 AC 6 ms
7,744 KB
testcase_20 AC 3 ms
7,744 KB
testcase_21 AC 4 ms
7,744 KB
testcase_22 AC 4 ms
7,744 KB
testcase_23 AC 4 ms
8,000 KB
testcase_24 AC 3 ms
7,872 KB
testcase_25 AC 4 ms
7,872 KB
testcase_26 AC 3 ms
7,744 KB
testcase_27 AC 4 ms
7,744 KB
testcase_28 AC 4 ms
7,872 KB
testcase_29 AC 4 ms
7,872 KB
testcase_30 AC 70 ms
27,200 KB
testcase_31 AC 59 ms
17,984 KB
testcase_32 AC 62 ms
18,112 KB
testcase_33 AC 68 ms
24,256 KB
testcase_34 AC 57 ms
15,424 KB
testcase_35 AC 70 ms
29,376 KB
testcase_36 AC 65 ms
29,376 KB
testcase_37 AC 63 ms
17,472 KB
testcase_38 AC 72 ms
23,360 KB
testcase_39 AC 79 ms
28,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//実際に列を比較するO(N log N)解法
ll@T;rep(T){ll@N,a=0;list<ll>A;list<ll>B;list<ll>C;fenwick<ll>t;t.malloc(N+1,1);rep(i,N){ll@P,c=t.range(0,P);if(c>i-c||A.empty())a+=i-c,A.push_back(P),B.push_back(P),C.push_back(P);else if(c<i-c) a+=c,A.push_front(P),B.push_front(P),C.push_front(P);else{B.push_front(P),C.push_back(P);if(B<C)a+=c,A.push_front(P),C.pop_back(),C.push_front(P);else a+=i-c,A.push_back(P),B.pop_front(),B.push_back(P);}t.add(P,1);}wt(a);auto j=A.begin(),e=A.end();while(j!=e)wtSp(*j++);wt("");}
0