結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー kappybarkappybar
提出日時 2020-07-17 21:46:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 1,654 bytes
コンパイル時間 2,616 ms
コンパイル使用メモリ 175,956 KB
実行使用メモリ 9,932 KB
最終ジャッジ日時 2023-08-20 00:26:54
合計ジャッジ時間 5,554 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 97 ms
8,772 KB
testcase_04 AC 113 ms
9,584 KB
testcase_05 AC 96 ms
8,664 KB
testcase_06 AC 88 ms
8,380 KB
testcase_07 AC 112 ms
9,612 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 48 ms
6,752 KB
testcase_10 AC 86 ms
9,680 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 114 ms
9,660 KB
testcase_13 AC 114 ms
9,932 KB
testcase_14 AC 115 ms
9,720 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 37 ms
5,384 KB
testcase_25 AC 83 ms
7,984 KB
testcase_26 AC 18 ms
4,396 KB
testcase_27 AC 46 ms
6,012 KB
testcase_28 AC 65 ms
6,956 KB
testcase_29 AC 88 ms
8,564 KB
testcase_30 AC 108 ms
9,432 KB
testcase_31 AC 25 ms
4,892 KB
testcase_32 AC 16 ms
4,392 KB
testcase_33 AC 95 ms
8,864 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;


//1-indexedに注意!!!
struct BIT{
    private:
    int n,n_;
    vector<long long> bit;

    public:
    BIT(int n):n(n){
        bit.resize(n+1);
        n_ = 1;
        while(n_<=n) n_<<=1;
        n_ >>= 1;
    }
    //1-index
    long long sum(int i){
        long long res = 0;
        while(i > 0){
            res += bit[i];
            i -= i&-i;
        }
        return res;
    }
    //1-index
    void add(int i,long long val){
        while(i <= n){
            bit[i] += val;
            i += i&-i;
        }
    }
    //return 1-index
    int lowerbound(long long w){
        if(w <= 0) return 0;
        int x = 0;
        for(int k=n_;k>0;k>>=1){
            if(x+k<=n&&bit[x+k]<w){
                w -= bit[x+k];
                x += k;
            }
        }
        return x+1;
    }
};



int main(){
        int n;
        cin >> n;
        vector<int> a(n),b(n);
        rep(i,n) cin >> a[i];
        rep(i,n) cin >> b[i];
        map<int,int> mp;
        rep(i,n) mp[b[i]] = i;
        vector<int> v(n);
        rep(i,n){
            v[i] = mp[a[i]];
        }
        BIT bit(n);
        ll ans = 0;
        rep(i,n){
                ans += i-bit.sum(v[i]+1);
                bit.add(v[i]+1,1);
        }
        cout << ans << endl;
        return 0;
}
                        
                        
0