結果
| 問題 |
No.2665 Minimize Inversions of Deque
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2023-12-30 13:28:15 |
| 言語 | cLay (20241019-1) |
| 結果 |
AC
|
| 実行時間 | 80 ms / 2,000 ms |
| コード長 | 520 bytes |
| コンパイル時間 | 2,710 ms |
| コンパイル使用メモリ | 179,296 KB |
| 実行使用メモリ | 27,204 KB |
| 最終ジャッジ日時 | 2024-09-27 19:07:04 |
| 合計ジャッジ時間 | 6,692 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 40 |
ソースコード
//実際に列を比較する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("");}