結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー yuuiyuui
提出日時 2020-07-17 22:11:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 946 bytes
コンパイル時間 2,497 ms
コンパイル使用メモリ 209,156 KB
実行使用メモリ 14,628 KB
最終ジャッジ日時 2023-08-20 01:31:56
合計ジャッジ時間 5,804 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 100 ms
14,032 KB
testcase_04 AC 124 ms
14,452 KB
testcase_05 AC 98 ms
13,720 KB
testcase_06 AC 83 ms
11,184 KB
testcase_07 AC 126 ms
14,552 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 50 ms
9,420 KB
testcase_10 AC 85 ms
14,628 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 122 ms
14,508 KB
testcase_13 AC 117 ms
14,564 KB
testcase_14 AC 122 ms
14,468 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 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,380 KB
testcase_23 AC 8 ms
4,384 KB
testcase_24 AC 36 ms
6,760 KB
testcase_25 AC 82 ms
10,712 KB
testcase_26 AC 17 ms
4,896 KB
testcase_27 AC 47 ms
8,600 KB
testcase_28 AC 64 ms
9,528 KB
testcase_29 AC 88 ms
11,188 KB
testcase_30 AC 113 ms
14,124 KB
testcase_31 AC 25 ms
5,756 KB
testcase_32 AC 16 ms
4,920 KB
testcase_33 AC 83 ms
13,772 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,384 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,384 KB
testcase_39 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;

template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};


int main() {
    ll N;
    cin >> N;
    vector<ll> A(N),B(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    unordered_map<ll,ll> Bmp; 
    for(int i=0;i<N;i++){
        ll B;
        cin >> B;
        Bmp[B] = i;
    }
    unordered_map<ll,ll> revA;
    for(int i=0;i<N;i++){
        A[i] = Bmp[A[i]];
        revA[A[i]] = i;
    }

    ll ans =0;
    BinaryIndexedTree<ll> bit(N+5);
    for(int i=0;i<N;i++){
        ans += (bit.sum(N-1) -bit.sum(revA[i]));
        bit.add(revA[i],1);
    }
    
    cout << ans << endl;


    return 0;
}
0