結果

問題 No.2029 Swap Min Max Min
ユーザー auauaauaua
提出日時 2022-08-05 21:46:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,389 bytes
コンパイル時間 1,620 ms
コンパイル使用メモリ 169,320 KB
実行使用メモリ 7,988 KB
最終ジャッジ日時 2023-10-14 00:07:40
合計ジャッジ時間 5,412 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 22 ms
4,496 KB
testcase_06 AC 44 ms
6,284 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 13 ms
4,348 KB
testcase_11 WA -
testcase_12 AC 30 ms
5,100 KB
testcase_13 WA -
testcase_14 AC 67 ms
7,396 KB
testcase_15 WA -
testcase_16 AC 65 ms
7,748 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 66 ms
7,400 KB
testcase_20 AC 67 ms
7,456 KB
testcase_21 AC 66 ms
7,448 KB
testcase_22 AC 65 ms
7,532 KB
testcase_23 AC 75 ms
7,852 KB
testcase_24 AC 74 ms
7,924 KB
testcase_25 AC 66 ms
7,928 KB
testcase_26 AC 66 ms
7,988 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 WA -
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 65 ms
7,272 KB
testcase_39 AC 64 ms
7,520 KB
testcase_40 AC 56 ms
7,132 KB
testcase_41 AC 68 ms
7,280 KB
testcase_42 AC 69 ms
7,340 KB
testcase_43 AC 62 ms
7,696 KB
testcase_44 AC 74 ms
7,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <unordered_set>
#include <random>
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
//#define vec vector<ll>
//#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=MOD;
const ll inv2=499122177;
const ll MAX=200010;
const double PI=acos(-1.0);
typedef vector<vector<ll> > mat;
typedef vector<ll> vec;

ll dx[]={0,1,0,-1,-1,-1,1,1};
ll dy[]={1,0,-1,0,-1,1,-1,1};

//Binary Indexes Tree
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};


void solve(){
    ll n;cin>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll ans1=0;
    {
        ll cnt1=0,cnt2=1;
        vector<ll>b(n);
        rep(i,n){
            if(a[i]>n/2){
                b[i]=cnt1;
                cnt1+=2;
            }else{
                b[i]=cnt2;
                cnt2+=2;
            }
        }
        BinaryIndexedTree<ll>bit(n);
        ll ans=0;
        rep(i,n){
            ll s=bit.sum(n-1);
            if(b[i])s-=bit.sum(b[i]);
            ans+=s;
            bit.add(b[i],1);
        }
        ans1=ans;
    }
    ll ans2=inf;
    if(n%2==0){
        ll cnt1=1,cnt2=0;
        vector<ll>b(n);
        rep(i,n){
            if(a[i]>n/2){
                b[i]=cnt1;
                cnt1+=2;
            }else{
                b[i]=cnt2;
                cnt2+=2;
            }
        }
        BinaryIndexedTree<ll>bit(n);
        ll ans=0;
        rep(i,n){
            ll s=bit.sum(n-1);
            if(b[i])s-=bit.sum(b[i]);
            ans+=s;
            bit.add(b[i],1);
        }
        ans2=ans;
    }
    cout<<n/2<<' '<<min(ans1,ans2)<<endl;
}

signed main(){
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    solve();
}
0