結果

問題 No.2029 Swap Min Max Min
ユーザー auauaauaua
提出日時 2022-08-05 21:43:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,758 bytes
コンパイル時間 1,750 ms
コンパイル使用メモリ 168,268 KB
実行使用メモリ 8,020 KB
最終ジャッジ日時 2023-10-14 00:06:54
合計ジャッジ時間 5,350 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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,656 KB
testcase_06 AC 45 ms
6,120 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 13 ms
4,348 KB
testcase_11 WA -
testcase_12 AC 29 ms
5,304 KB
testcase_13 WA -
testcase_14 AC 67 ms
7,460 KB
testcase_15 WA -
testcase_16 AC 65 ms
7,400 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 66 ms
7,600 KB
testcase_20 AC 67 ms
7,436 KB
testcase_21 AC 66 ms
7,612 KB
testcase_22 AC 65 ms
7,440 KB
testcase_23 WA -
testcase_24 AC 66 ms
7,856 KB
testcase_25 AC 66 ms
7,808 KB
testcase_26 AC 66 ms
7,860 KB
testcase_27 WA -
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 WA -
testcase_33 AC 2 ms
4,348 KB
testcase_34 WA -
testcase_35 AC 1 ms
4,352 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 64 ms
7,616 KB
testcase_40 AC 57 ms
6,932 KB
testcase_41 AC 61 ms
7,336 KB
testcase_42 AC 60 ms
7,176 KB
testcase_43 AC 62 ms
7,404 KB
testcase_44 AC 66 ms
8,020 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 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);
    }
    cout<<n/2<<' '<<ans<<endl;
}

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