結果
問題 | No.2665 Minimize Inversions of Deque |
ユーザー | 矢澤式WINTER |
提出日時 | 2024-03-08 22:53:53 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 103 ms / 2,000 ms |
コード長 | 1,456 bytes |
コンパイル時間 | 6,250 ms |
コンパイル使用メモリ | 312,532 KB |
実行使用メモリ | 6,676 KB |
最終ジャッジ日時 | 2024-03-08 22:54:05 |
合計ジャッジ時間 | 9,971 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,676 KB |
testcase_01 | AC | 103 ms
6,676 KB |
testcase_02 | AC | 100 ms
6,676 KB |
testcase_03 | AC | 94 ms
6,676 KB |
testcase_04 | AC | 93 ms
6,676 KB |
testcase_05 | AC | 97 ms
6,676 KB |
testcase_06 | AC | 93 ms
6,676 KB |
testcase_07 | AC | 93 ms
6,676 KB |
testcase_08 | AC | 93 ms
6,676 KB |
testcase_09 | AC | 93 ms
6,676 KB |
testcase_10 | AC | 93 ms
6,676 KB |
testcase_11 | AC | 94 ms
6,676 KB |
testcase_12 | AC | 93 ms
6,676 KB |
testcase_13 | AC | 94 ms
6,676 KB |
testcase_14 | AC | 94 ms
6,676 KB |
testcase_15 | AC | 96 ms
6,676 KB |
testcase_16 | AC | 93 ms
6,676 KB |
testcase_17 | AC | 94 ms
6,676 KB |
testcase_18 | AC | 94 ms
6,676 KB |
testcase_19 | AC | 15 ms
6,676 KB |
testcase_20 | AC | 3 ms
6,676 KB |
testcase_21 | AC | 3 ms
6,676 KB |
testcase_22 | AC | 3 ms
6,676 KB |
testcase_23 | AC | 3 ms
6,676 KB |
testcase_24 | AC | 3 ms
6,676 KB |
testcase_25 | AC | 3 ms
6,676 KB |
testcase_26 | AC | 3 ms
6,676 KB |
testcase_27 | AC | 3 ms
6,676 KB |
testcase_28 | AC | 3 ms
6,676 KB |
testcase_29 | AC | 3 ms
6,676 KB |
testcase_30 | AC | 44 ms
6,676 KB |
testcase_31 | AC | 42 ms
6,676 KB |
testcase_32 | AC | 42 ms
6,676 KB |
testcase_33 | AC | 44 ms
6,676 KB |
testcase_34 | AC | 42 ms
6,676 KB |
testcase_35 | AC | 44 ms
6,676 KB |
testcase_36 | AC | 42 ms
6,676 KB |
testcase_37 | AC | 42 ms
6,676 KB |
testcase_38 | AC | 43 ms
6,676 KB |
testcase_39 | AC | 45 ms
6,676 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; //*/ #include <atcoder/all> using namespace atcoder; //*/ #define rep(i,n) for(int i=0;i<n;i++) #define Rep(i,a,b) for(int i=a;i<b;i++) #define ALL(x) (x).begin(),(x).end() #define dbgv(x); for(auto now : x) cout << now << " "; cout << endl; //using P = pair<int,int>; using ll = long long; using ull = unsigned long long; //*/ template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<int> vint; void solve(){ int n; cin >> n; vint p(n); rep(i,n) cin >> p[i]; fenwick_tree<int> fw(n+1); ll c = 0; deque<int> ans; ans.push_back(p[0]); fw.add(p[0],1); rep(i,n-1){ int now = p[i+1]; int m = fw.sum(0,now); int M = ans.size()-m; //cout << "l : +" << m << " r : +" << M << endl; if(M > m){ c += m; ans.push_front(now); }else if(M < m){ c += M; ans.push_back(now); }else{ //cout << "! : " << now << endl; if(ans.front() > now) ans.push_front(now); else ans.push_back(now); c += m; } fw.add(now,1); } cout << c << endl; for(auto now : ans) cout << now << " "; cout << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; cin >> t; rep(_,t) solve(); }