結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー fastmathfastmath
提出日時 2020-07-17 21:32:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 1,387 ms
コンパイル使用メモリ 165,964 KB
実行使用メモリ 7,388 KB
最終ジャッジ日時 2024-05-07 07:12:11
合計ジャッジ時間 2,883 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 18 ms
6,784 KB
testcase_04 AC 21 ms
7,388 KB
testcase_05 AC 19 ms
6,656 KB
testcase_06 AC 17 ms
6,400 KB
testcase_07 AC 21 ms
7,040 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 12 ms
5,504 KB
testcase_10 AC 20 ms
7,296 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 22 ms
7,296 KB
testcase_13 AC 23 ms
7,264 KB
testcase_14 AC 22 ms
7,264 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 8 ms
5,376 KB
testcase_25 AC 15 ms
6,272 KB
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 11 ms
5,376 KB
testcase_28 AC 13 ms
5,760 KB
testcase_29 AC 18 ms
6,528 KB
testcase_30 AC 20 ms
7,040 KB
testcase_31 AC 6 ms
5,376 KB
testcase_32 AC 6 ms
5,376 KB
testcase_33 AC 19 ms
6,656 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,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