結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー fastmathfastmath
提出日時 2020-07-17 21:32:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 1,373 ms
コンパイル使用メモリ 164,696 KB
実行使用メモリ 7,368 KB
最終ジャッジ日時 2023-08-19 23:54:12
合計ジャッジ時間 3,332 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 22 ms
6,736 KB
testcase_04 AC 25 ms
7,292 KB
testcase_05 AC 21 ms
6,944 KB
testcase_06 AC 20 ms
6,544 KB
testcase_07 AC 25 ms
7,272 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 14 ms
5,624 KB
testcase_10 AC 23 ms
7,340 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 25 ms
7,268 KB
testcase_13 AC 25 ms
7,368 KB
testcase_14 AC 25 ms
7,340 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 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,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 10 ms
4,776 KB
testcase_25 AC 18 ms
6,300 KB
testcase_26 AC 5 ms
4,380 KB
testcase_27 AC 12 ms
5,228 KB
testcase_28 AC 15 ms
5,744 KB
testcase_29 AC 20 ms
6,492 KB
testcase_30 AC 23 ms
7,080 KB
testcase_31 AC 7 ms
4,376 KB
testcase_32 AC 6 ms
4,380 KB
testcase_33 AC 21 ms
6,856 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 1e5+7;

struct Fen {
int f[N];
void clear() {
    for (int i = 0; i < N; ++i) f[i] = 0;
}   
void add(int i, int x) {
    for (; i < N; i |= i + 1) 
        f[i] += x;
}   
int get(int i) {
    int ans = 0;
    for (; i >= 0; i &= i + 1, --i) ans += f[i];
    return ans;
}   
int get(int l, int r) {
    return get(r) - get(l - 1);
}   
} f;

int a[N], b[N], to[N];
int bpos[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }   
    for (int i = 1; i <= n; ++i) {
        cin >> b[i];
        bpos[b[i]] = i;
    }   

    for (int i = 1; i <= n; ++i)
        to[i] = bpos[a[i]];

    int ans = 0;
    for (int i = n; i; --i) {
        ans += f.get(to[i]);
        f.add(to[i], 1);
    }   
    cout << ans << endl;
}
0