結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー Manuel1024Manuel1024
提出日時 2021-04-03 03:10:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 1,098 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 82,756 KB
実行使用メモリ 9,756 KB
最終ジャッジ日時 2023-08-25 17:52:22
合計ジャッジ時間 7,173 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 105 ms
8,952 KB
testcase_04 AC 121 ms
9,580 KB
testcase_05 AC 102 ms
8,496 KB
testcase_06 AC 93 ms
8,420 KB
testcase_07 AC 119 ms
9,568 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 50 ms
6,788 KB
testcase_10 AC 88 ms
9,576 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 119 ms
9,548 KB
testcase_13 AC 121 ms
9,552 KB
testcase_14 AC 122 ms
9,756 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 9 ms
4,380 KB
testcase_24 AC 38 ms
5,512 KB
testcase_25 AC 85 ms
7,968 KB
testcase_26 AC 19 ms
4,380 KB
testcase_27 AC 48 ms
5,984 KB
testcase_28 AC 68 ms
6,936 KB
testcase_29 AC 93 ms
8,308 KB
testcase_30 AC 116 ms
9,312 KB
testcase_31 AC 26 ms
4,728 KB
testcase_32 AC 16 ms
4,384 KB
testcase_33 AC 102 ms
8,844 KB
testcase_34 AC 2 ms
4,384 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
using namespace std;
using ll = long long int;

class BIT{
private:
    vector<ll> a;
    int n;
public:
    BIT(int len){
        a = vector<ll>(len+1, 0);
        n = len;
    }

    void add(int ind, ll x){
        ind++;
        while(ind <= n){
            a[ind] += x;
            ind += ind & (-ind);
        }
    }

    ll sum_sub(int end){
        end++;
        ll ans = 0;
        while(end > 0){
            ans += a[end];
            end -= end & (-end);
        }
        return ans;
    }

    ll sum(int start, int end){
        return sum_sub(end)-sum_sub(start-1);
    }
};

int main(){
    int n;
    cin >> n;
    vector<int> a0(n), b(n);
    for(auto &p: a0) cin >> p;
    for(auto &p: b) cin >> p;

    map<int, int> memo;
    for(int i = 0; i < n; i++) memo[b[i]] = i;

    vector<int> a(n);
    for(int i = 0; i < n; i++) a[i] = memo[a0[i]];

    BIT data(n);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        data.add(a[i], 1);
        ans += data.sum(a[i], n-1)-1;
    }

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