結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー ShibuyapShibuyap
提出日時 2020-07-18 20:46:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 1,136 bytes
コンパイル時間 2,937 ms
コンパイル使用メモリ 206,728 KB
実行使用メモリ 9,508 KB
最終ジャッジ日時 2023-08-20 23:40:13
合計ジャッジ時間 6,454 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 115 ms
8,284 KB
testcase_04 AC 138 ms
9,128 KB
testcase_05 AC 117 ms
8,324 KB
testcase_06 AC 104 ms
7,828 KB
testcase_07 AC 136 ms
9,056 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 53 ms
6,732 KB
testcase_10 AC 94 ms
9,508 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 138 ms
9,320 KB
testcase_13 AC 140 ms
9,368 KB
testcase_14 AC 144 ms
9,436 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,504 KB
testcase_20 AC 2 ms
4,504 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 42 ms
5,404 KB
testcase_25 AC 97 ms
7,784 KB
testcase_26 AC 20 ms
4,508 KB
testcase_27 AC 53 ms
5,912 KB
testcase_28 AC 77 ms
6,960 KB
testcase_29 AC 106 ms
8,040 KB
testcase_30 AC 130 ms
8,836 KB
testcase_31 AC 29 ms
5,020 KB
testcase_32 AC 19 ms
4,680 KB
testcase_33 AC 108 ms
8,572 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,384 KB
testcase_39 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}

ll mergecount(vector<int> &a) {
    ll count = 0;
    int n = a.size();
    if (n > 1) {
        vector<int> b(a.begin(), a.begin() + n/2);
        vector<int> c(a.begin() + n/2, a.end());
        count += mergecount(b);
        count += mergecount(c);
        for (int i = 0, j = 0, k = 0; i < n; ++i)
        if (k == c.size())       a[i] = b[j++];
        else if (j == b.size())  a[i] = c[k++];
        else if (b[j] <= c[k])   a[i] = b[j++];
        else                   { a[i] = c[k++]; count += n/2 - j; }
    }
    return count;
}

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int b[n];
    rep(i,n)cin >> b[i];

    map<int,int> mp;
    rep(i,n){
        mp[b[i]] = i+1;
    }

    rep(i,n){
        a[i] = mp[a[i]];
    }

    ll ans = mergecount(a); 

    cout << ans << endl;
    return 0;
}
 
 
0